1

我正在尝试链接libpng16.lib到我的 .dll 文件,但我无法让它工作。我已经包含libpng16.libzlib.lib进入项目依赖项(以正确的顺序,首先是 libpng),但仍然会出现png_*链接错误。

即使我在谷歌搜索的其他解决方案也不起作用。

编辑:

这是日志:

mingw32-g++.exe -Wall  -O2  -std=c++11 -Wall -g    -c C:\Users\Mark\Documents\CodeBlocks\TextureLoader\TextureLoader.cpp -o obj\Release\TextureLoader.o
C:\Users\Mark\Documents\CodeBlocks\TextureLoader\TextureLoader.cpp: In static member function 'static unsigned int TextureLoader::PNG_Texture_Load(const char*)':
C:\Users\Mark\Documents\CodeBlocks\TextureLoader\TextureLoader.cpp:105:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
mingw32-g++.exe -shared  -Wl,--out-implib=bin\Release\libTextureLoader.a -Wl,--dll -LC:\MinGW\include  obj\Release\TextureLoader.o   -o bin\Release\TextureLoader.dll -lOpenGL32 -lGLu32 -s  C:\Users\Mark\Documents\CodeBlocks\TextureLoader\libpng16.lib C:\Users\Mark\Documents\CodeBlocks\TextureLoader\libpng16.lib 
obj\Release\TextureLoader.o: In function `ZN13TextureLoader16PNG_Texture_LoadEPKc':
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:27: undefined reference to `png_sig_cmp'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:33: undefined reference to `png_create_read_struct'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:41: undefined reference to `png_create_info_struct'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:50: undefined reference to `png_create_info_struct'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:59: undefined reference to `png_set_longjmp_fn'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:66: undefined reference to `png_init_io'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:68: undefined reference to `png_set_sig_bytes'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:70: undefined reference to `png_read_info'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:77: undefined reference to `png_get_IHDR'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:79: undefined reference to `png_read_update_info'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:81: undefined reference to `png_get_rowbytes'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:109: undefined reference to `png_read_image'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:123: undefined reference to `png_destroy_read_struct'
C:/Users/Mark/Documents/CodeBlocks/TextureLoader/TextureLoader.cpp:100: undefined reference to `png_destroy_read_struct'
4

1 回答 1

0

链接期间未定义的符号通常表明您尝试链接的导入库有问题,或者工具集正在寻找的内容与导入实际提供的符号之间存在分歧。

说了这么多,mingw自带的gnu ld链接器应该可以看懂msvc.lib导入库了。作为替代方案,您可以尝试libpng16.dll通过将其传递给链接器来直接链接。

例如,尝试使用以下命令链接:

g++.exe -shared -Wl,--out-implib=bin\Release\libTextureLoader.a -LC:\MinGW\include obj\Release\TextureLoader.o -o bin\Release\TextureLoader.dll -lOpenGL32 -lGLu32 路径\ location\of\your\libpng16.dll

请注意,-LC:\MinGW\include在您的原始链接命令中可能不正确。直接包含运行时和其他各种导入的库路径通常位于 mingw 的 lib 目录中,而不是包含目录中。例如,地雷位于G:\Mingw32-4.6.3\i686-w64-mingw32\lib.

于 2013-05-17T03:39:19.010 回答