【发布时间】:2016-12-15 11:50:43
【问题描述】:
我正在关注this 示例。但是,我想为给定的玩具示例代码编译一个静态二进制文件。通常,我在编译期间使用-static,但在这里它会给出错误消息。
运行良好的编译命令:
g++ freeimagetest.cpp -o freeimagetest -lfreeimageplus
没有的编译命令可以正常工作:
g++ freeimagetest.cpp -o freeimagetest -lfreeimageplus -static
错误信息的最后几行:
In function `ZIPPreDecode':
(.text+0x6f8): undefined reference to `inflateReset'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libfreeimageplus.a(tif_zip.o): In function `ZIPSetupDecode':
(.text+0x783): undefined reference to `inflateInit_'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libfreeimageplus.a(tif_zip.o): In function `ZIPSetupDecode':
(.text+0x7b4): undefined reference to `deflateEnd'
collect2: ld returned 1 exit status
那么如何做到/解决这个问题?
编辑:我看不到附加的链接如何解决我的问题。显然,由于错误消息,我尝试静态编译它的方式存在一些问题。我找不到这样做的正确方法。我认为错误消息具有误导性 - 它仅以这些行结尾(这些行不到所有消息的百分之一)。做过的人可以更好的回答。如果您认为您的答案不仅仅是一个有根据的猜测,我会要求您在回答之前先试一试。如果您点击随附的链接,则只需几分钟。此外,我还标记了C,因为它对于 C 语言程序也是一样的。
【问题讨论】:
标签: c++ c static-libraries static-linking freeimage