在 windows 上构建 mathgl

Building mathgl on windows

我是 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 源代码的脚本目录中复制预构建的 pnglibconf.h 来修复第一个错误。在那之后,MinGW header rpcndr.h 中字节的定义似乎干扰了 oPRCFile.cc 中的 byte(double) 方法,我只是通过将方法重命名为 byteN 并从宏中调用它 (#define byte(c) byteN(c))。虽然这可能不是正确的方法,但它确实有效。

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

编辑:好的,已编译。于是我复制了libmgl.a,放到我要用的项目中吧。我通过调用 target_link_libraries(Test ${CMAKE_SOURCE_DIR}/libmgl.a) 将它与 cmake 链接起来,但它只会抛出一堆 undefined reference to 错误(如果我使用预编译的二进制文件也是如此):

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'
[...]

看起来缺少的头文件是在 运行 为 libpng 进行配置后生成的(在 Windows 下你可能无法这样做,需要自己生成 -> Cannot open include file: 'pnglibconf.h':No such file or directory )

但除此之外,您是如何得到需要从头开始构建它才能使用它的印象的?您还可以下载预编译的二进制文件并 link 它们与您的程序一起使用(http://mathgl.sourceforge.net/doc_en/Installation.html - 第 2 点)。

编辑:查看您的编辑,您需要在 Windows 中指定实际的库文件(可能类似于 png32.a 或您的 libpng 编译生成的任何内容),假设 linker还有库文件所在的路径(见http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use