前提
C++でグラフを描画できたらと思い,リンク先にあるImPlotというライブラリ( https://github.com/epezent/implot )を使って,リンク先のgithubの中でdemoとして公開されているような,正弦波のグラフと棒グラフを出力してみようと思い下のようなコードで"CMakeLists.txt"を書いて"cmake --build ."のコマンドでビルドしようとしたところ以下のようなメッセージが出ました.
ファイル構成に関しては以下のような感じです.
test_implot
| main.cpp
| CMakeLists.txt
├─build
└─imgui
buildに関してはwindowsのコマンドプロンプトでbuildファイル内に移動し,"cmake .."コマンドを実行後,続いて"cmake --build ."のコマンドを打ったというような状況です.
imguiファイルについてはimguiのライブラリ( https://github.com/ocornut/imgui )をクローンした後,implot
( https://github.com/epezent/implot )内のファイルをすべてコピペして貼り付けたものになります.
実現したいこと
・ImPlotを使ってとりあえず正弦波のグラフ,棒グラフをウィンドウに出力してみたい.
発生している問題・エラーメッセージ
CMake is re-running because C:/Users/PCUSER/Documents/cpp/test_implot/build/CMakeFiles/generate.stamp is out-of-date. the file 'C:/Users/PCUSER/Documents/cpp/test_implot/CMakeLists.txt' is newer than 'C:/Users/PCUSER/Documents/cpp/test_implot/build/CMakeFiles/generate.stamp.depend' result='-1' -- Configuring done -- Generating done -- Build files have been written to: C:/Users/PCUSER/Documents/cpp/test_implot/build Consolidate compiler generated dependencies of target plotTest [ 12%] Building CXX object CMakeFiles/plotTest.dir/main.cpp.obj [ 25%] Building CXX object CMakeFiles/plotTest.dir/imgui/implot.cpp.obj C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp: In function 'ImPlotTime ImPlot::MkGmtTime(tm*)': C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp:882:11: error: '_mkgmtime' was not declared in this scope; did you mean 'gmtime'? 882 | t.S = _mkgmtime(ptm); | ^~~~~~~~~ | gmtime C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp: In function 'tm* ImPlot::GetGmtTime(const ImPlotTime&, tm*)': C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp:893:7: error: 'gmtime_s' was not declared in this scope; did you mean 'gmtime'? 893 | if (gmtime_s(ptm, &t.S) == 0) | ^~~~~~~~ | gmtime C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp: In function 'tm* ImPlot::GetLocTime(const ImPlotTime&, tm*)': C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp:912:7: error: 'localtime_s' was not declared in this scope; did you mean 'localtime'? 912 | if (localtime_s(ptm, &t.S) == 0) | ^~~~~~~~~~~ | localtime C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp: In function 'void ImPlot::Locator_Time(ImPlotTicker&, const ImPlotRange&, float, bool, ImPlotFormatter, void*)': C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp:1232:68: warning: NULL used in arithmetic [-Wpointer-arith] 1232 | ftd.Time = t1; ftd.Spec = last_major_offset < 0 == NULL ? fmtf : fmt1; | ^~~~ C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp: In function 'tm* ImPlot::GetGmtTime(const ImPlotTime&, tm*)': C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp:900:1: warning: control reaches end of non-void function [-Wreturn-type] 900 | } | ^ C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp: In function 'tm* ImPlot::GetLocTime(const ImPlotTime&, tm*)': C:\Users\PCUSER\Documents\cpp\test_implot\imgui\implot.cpp:919:1: warning: control reaches end of non-void function [-Wreturn-type] 919 | } | ^ CMakeFiles\plotTest.dir\build.make:88: recipe for target 'CMakeFiles/plotTest.dir/imgui/implot.cpp.obj' failed mingw32-make.exe[2]: *** [CMakeFiles/plotTest.dir/imgui/implot.cpp.obj] Error 1 CMakeFiles\Makefile2:837: recipe for target 'CMakeFiles/plotTest.dir/all' failed mingw32-make.exe[1]: *** [CMakeFiles/plotTest.dir/all] Error 2 Makefile:119: recipe for target 'all' failed mingw32-make.exe: *** [all] Error 2
該当のソースコード
C++
1#include "imgui/implot.h" 2#include <iostream> 3#include <math.h> 4 5int main() { 6 static float xs1[1001], ys1[1001]; 7 for (int i = 0; i < 1001; ++i) { 8 xs1[i] = i * 0.001f; 9 ys1[i] = 0.5f + 0.5f * sinf(50 * (xs1[i] + (float)ImGui::GetTime() / 10)); 10 } 11 static double xs2[20], ys2[20]; 12 for (int i = 0; i < 20; ++i) { 13 xs2[i] = i * 1/19.0f; 14 ys2[i] = xs2[i] * xs2[i]; 15 } 16 if (ImPlot::BeginPlot("Line Plots")) { 17 ImPlot::SetupAxes("x","y"); 18 ImPlot::PlotLine("f(x)", xs1, ys1, 1001); 19 ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle); 20 ImPlot::PlotLine("g(x)", xs2, ys2, 20,ImPlotLineFlags_Segments); 21 ImPlot::EndPlot(); 22 } 23}
CMakeLists.txt
1cmake_minimum_required(VERSION 3.0.0) 2project(plotTest VERSION 0.1.0) 3 4include(CTest) 5enable_testing() 6 7add_executable(plotTest main.cpp imgui/implot.cpp imgui/implot_items.cpp imgui/imgui.cpp imgui/imgui_widgets.cpp imgui/imgui_tables.cpp imgui/imgui_draw.cpp) 8 9set(CPACK_PROJECT_NAME ${PROJECT_NAME}) 10set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) 11include(CPack) 12
CMakeLists.txtに関しては何とかネットで集めた知識を寄せ集めて書いたものです.もしかして,ここに問題があるのでしょうか?
ライブラリを使うのは初めてで,何とかbuildしようとしてたどり着いた結果がこれでした.
試したこと
implot.cpp ないで,time.h が include されていないのが原因かと思い,#include <time.h> を加えて同じ手順でbuildしようとしてみたのですがうまくいきませんでした.上記のエラーメッセージはtime.hのincludeを書き加えたうえで出力されたメッセージです.
補足情報(FW/ツールのバージョンなど)
windows 11 pro 21H2
VSCODE 1.69.2
C++17

回答1件
あなたの回答
tips
プレビュー