在windows上构建mathgl

时间:2017-04-09 09:44:25

标签: c++ mathgl

我是C ++的新手(曾经是​​Java开发人员,这更容易......)我必须编写一个应用程序,它必须绘制一些图形和图表。为此,我想使用MathGL库。我了解到,我必须自己编译才能使用它。这就是我过去几天试图做的事情......

我正在使用Windows与MinGW和CLion IDE。 我首先将MathGL的源代码解压缩到一个文件夹中,然后用CLion打开文件夹。 然后我下载了zlib和libpng的源代码,并将MathGL项目中的INCLUDE_DIR变量设置为相应的文件夹,将PNG_PNG_LIBRARY设置为png32。当我尝试通过CLion编译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源代码的scripts目录中复制预构建的pnglibconf.h来修复第一个错误。之后,MinGW标头rpcndr.h中的字节定义似乎干扰了byte(double)中的oPRCFile.cc方法,我只是通过将方法重命名为byteN并调用它来解决这个问题。从宏(#define byte(c) byteN(c))。虽然这可能不是正确的方法,但它确实有效。

但是所有修复了链接器似乎都被错误地配置了:它说cannot find -lpng32。我该如何解决这个问题?

编辑:好的,它已编译完成。所以我复制了libmgl.a并将其放入我想要使用它的项目中。我通过调用target_link_libraries(Test ${CMAKE_SOURCE_DIR}/libmgl.a)与cmake链接它,但它只会引发一堆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'
[...]

1 个答案:

答案 0 :(得分: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