Code :: Blocks w / MinGW:将libpng静态链接到dll

时间:2013-05-15 10:52:47

标签: c++ c++11 mingw codeblocks libpng

我正在尝试将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'

1 个答案:

答案 0 :(得分: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路径\位置\ \ your \ libpng16.dll

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