在窗户上建造数学

Building mathgl on windows

本文关键字:窗户      更新时间:2023-10-16

我对C++有点陌生(以前是Java开发人员,这更容易......),我必须编写一个应用程序,它必须绘制一些图形和图表。为此,我想使用 MathGL 库。我了解到,我必须自己编译才能使用它。这就是我最近几天想做的事情......

我正在使用带有MinGW和CLion IDE的Windows。 我首先将 MathGL 的源代码提取到一个文件夹中,然后使用 CLion 打开该文件夹。 然后我下载了 zlib 和 libpng 的源代码,并将 MathGL 项目中的INCLUDE_DIR变量设置为各自的文件夹,PNG_PNG_LIBRARY为 png32。当我尝试通过 CLion 编译mgl_example时,它给了我以下错误:

In file included from [...]mathgl-2.3.5.1srcdata_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....
srcCMakeFilesmgl.dirbuild.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
CMakeFilesMakefile2: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并将其放入我想使用它的项目中。我通过调用 cmaketarget_link_libraries(Test ${CMAKE_SOURCE_DIR}/libmgl.a)链接到它,但它只是抛出一堆undefined reference to错误(如果我使用预编译二进制文件也是如此):

MakeFilesTest.dir/objects.a(main.cpp.obj): In function `ZN8mglDataAC2Ev':
c:/mingw/include/mgl2/abstract.h:156: undefined reference to `_imp___ZTV8mglDataA'
CMakeFilesTest.dir/objects.a(main.cpp.obj): In function `ZN8mglDataAD2Ev':
c:/mingw/include/mgl2/abstract.h:157: undefined reference to `_imp___ZTV8mglDataA'
[...]

看起来在运行 libpng 配置后会生成丢失的头文件(在 Windows 下,您可能无法执行此操作,需要自己生成 ->无法打开包含文件:"pnglibconf.h":没有这样的文件或目录)

但除此之外,您是如何获得需要从头开始构建它才能使用它的印象的?您还可以下载预编译的二进制文件并将它们与您的程序链接(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)