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
助けていただければ幸いです。