我在开发自己的基于libpng(1.5 版本)的应用程序时遇到了问题。
长话短说,我需要静态链接这个库,但我不断收到“未定义的引用”错误。我尝试提取libpng15.a并将其内容添加到我的库以及使用 gcc 命令链接。
我的 gcc 命令:
gcc test.c librimg.a libz.a libpng15.a -o test -std=c99 -lglfw -lGL -lGLU
我得到的错误:
libpng15.a(libpng15_la-png.o): In function `png_reset_crc':
/home/robin/Downloads/libpng-1.5.12/png.c:111: undefined reference to `crc32'
libpng15.a(libpng15_la-png.o): In function `png_calculate_crc':
/home/robin/Downloads/libpng-1.5.12/png.c:152: undefined reference to `crc32'
libpng15.a(libpng15_la-png.o): In function `png_reset_zstream':
/home/robin/Downloads/libpng-1.5.12/png.c:757: undefined reference to `inflateReset'
libpng15.a(libpng15_la-pngread.o): In function `png_create_read_struct_2':
/home/robin/Downloads/libpng-1.5.12/pngread.c:119: undefined reference to `inflateInit_'
libpng15.a(libpng15_la-pngread.o): In function `png_read_row':
/home/robin/Downloads/libpng-1.5.12/pngread.c:557: undefined reference to `inflate'
libpng15.a(libpng15_la-pngread.o): In function `png_read_destroy':
/home/robin/Downloads/libpng-1.5.12/pngread.c:1070: undefined reference to `inflateEnd'
libpng15.a(libpng15_la-pngrutil.o): In function `png_inflate':
/home/robin/Downloads/libpng-1.5.12/pngrutil.c:333: undefined reference to `inflate'
/home/robin/Downloads/libpng-1.5.12/pngrutil.c:362: undefined reference to `inflateReset'
libpng15.a(libpng15_la-pngrutil.o): In function `png_read_finish_row':
/home/robin/Downloads/libpng-1.5.12/pngrutil.c:3848: undefined reference to `inflate'
/home/robin/Downloads/libpng-1.5.12/pngrutil.c:3880: undefined reference to `inflateReset'
collect2: ld returned 1 exit status
(注意:我已经从源代码编译库,目录/home/robin/Downloads/libpng-1.5.12/是我提取档案的地方。)
值得一提的是,我可以毫无困难地链接到共享库:
gcc test.c librimg.a -o test -std=c99 -lpng15 -lglfw -lGL -lGLU
我将不胜感激任何帮助。