我對C++很陌生(曾經是一個Java開發人員,這很容易......),我必須編寫一個應用程序,它必須繪製一些圖表和圖表。爲此,我想使用MathGL庫。我瞭解到,我必須自己編譯才能使用它。所以這就是我最近幾天想要做的...在窗口上構建mathgl
我在MinGW和CLion IDE上使用Windows。 我首先將MathGL的源代碼提取到一個文件夾中,然後用CLion打開文件夾。 然後我下載了zlib和libpng的源代碼,並將MathGL項目中的INCLUDE_DIR變量設置爲相應的文件夾,將PNG_PNG_LIBRARY設置爲png32。當我嘗試通過克利翁編譯mgl_example它給了我下面的錯誤:
In file included from [...]\mathgl-2.3.5.1\src\data_png.cpp:22:0:
[...]/libpng-1.6.29/png.h:361:27: fatal error: pnglibconf.h: No such file or directory
compilation terminated.
mingw32-make.exe[2]: *** [src/CMakeFiles/mgl.dir/data_png.cpp.obj] Error 1
mingw32-make.exe[2]: *** Waiting for unfinished jobs....
src\CMakeFiles\mgl.dir\build.make:465: recipe for target 'src/CMakeFiles/mgl.dir/data_png.cpp.obj' failed
mingw32-make.exe[2]: Leaving directory '[..]/mathgl-2.3.5.1/cmake-build-debug'
mingw32-make.exe[1]: *** [src/CMakeFiles/mgl.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
CMakeFiles\Makefile2:89: recipe for target 'src/CMakeFiles/mgl.dir/all' failed
mingw32-make.exe[1]: Leaving directory '[...]/mathgl-2.3.5.1/cmake-build-debug'
Makefile:129: recipe for target 'all' failed
編輯:我設法從libpng的源代碼的腳本目錄複製預建pnglibconf.h
來修復第一個錯誤。之後,MinGW頭部rpcndr.h
中的字節定義似乎干擾oPRCFile.cc
中的byte(double)
方法,我剛剛通過將方法重命名爲byteN
並從宏調用它(#define byte(c) byteN(c)
)來修復該方法。雖然這可能不是正確的路,但它是有效的。
但是,所有固定鏈接器似乎配置錯誤:它說cannot find -lpng32
。我該如何解決這個問題?
編輯:好的,它的編譯。所以我複製libmgl.a並將其放入我想用它的項目中。我鏈接的是它的cmake調用target_link_libraries(Test ${CMAKE_SOURCE_DIR}/libmgl.a)
但它只是拋出一堆undefined reference to
錯誤的(相同的,如果我使用procompiled二進制文件):
MakeFiles\Test.dir/objects.a(main.cpp.obj): In function `ZN8mglDataAC2Ev':
c:/mingw/include/mgl2/abstract.h:156: undefined reference to `_imp___ZTV8mglDataA'
CMakeFiles\Test.dir/objects.a(main.cpp.obj): In function `ZN8mglDataAD2Ev':
c:/mingw/include/mgl2/abstract.h:157: undefined reference to `_imp___ZTV8mglDataA'
[...]
謝謝。我編輯了這篇文章。儘管可能使用預編譯的二進制文件,但我仍然希望能夠實現這一點,因爲稍後可能會有用。 – aquaatic
誠然,作爲一種學習體驗,它不壞,但取決於你打算使用的庫,如果你依賴預編譯的二進制文件,特別是在Windows上,通常在*上使用的庫,可能會更容易(並節省時間)尼克斯系統。 – user2047610
那麼,我會再試一次(因爲預編譯的二進制文件確實包含,我需要) - 編輯:我做了,它不起作用。我把所有的東西放在我的MinGW文件夾中,使用'target_link_libraries(Test libmgl.a)'鏈接我的.exe文件,它只是拋出一堆未定義的引用錯誤。 – aquaatic