2017-04-09 53 views
0

我對C++很陌生(曾經是一個Java開發人員,這很容易......),我必須編寫一個應用程序,它必須繪製一些圖表和圖表。爲此,我想使用MathGL庫。我瞭解到,我必須自己編譯才能使用它。所以這就是我最近幾天想要做的...在窗口上構建mathgl

我在MinGW和CLion IDE上使用W​​indows。 我首先將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' 
[...] 

回答

0

看起來運行的libpng一個配置後,生成缺少的頭文件(在Windows下你可能無法做,需要自己生成 - >Cannot open include file: 'pnglibconf.h':No such file or directory

但是除此之外,你是怎麼覺得你需要從頭開始構建它才能使用它的?您也可以下載預編譯的二進制文件並將它們與您的程序鏈接(http://mathgl.sourceforge.net/doc_en/Installation.html - 點2)。你可能需要在Windows中指定實際的庫文件(可能是沿着png32.a的行或者你的libpng編譯生成的任何東西),假設鏈接器也有庫文件的路徑是(見http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use

+0

謝謝。我編輯了這篇文章。儘管可能使用預編譯的二進制文件,但我仍然希望能夠實現這一點,因爲稍後可能會有用。 – aquaatic

+0

誠然,作爲一種學習體驗,它不壞,但取決於你打算使用的庫,如果你依賴預編譯的二進制文件,特別是在Windows上,通常在*上使用的庫,可能會更容易(並節省時間)尼克斯系統。 – user2047610

+0

那麼,我會再試一次(因爲預編譯的二進制文件確實包含,我需要) - 編輯:我做了,它不起作用。我把所有的東西放在我的MinGW文件夾中,使用'target_link_libraries(Test libmgl.a)'鏈接我的.exe文件,它只是拋出一堆未定義的引用錯誤。 – aquaatic