I am following this example. However, I want to compile a static binary for the given toy example code. Normally, I use -static
during compilation but here it gives an error message.
The compile command which works fine:
g++ freeimagetest.cpp -o freeimagetest -lfreeimageplus
The compile command which does not works fine:
g++ freeimagetest.cpp -o freeimagetest -lfreeimageplus -static
The last few lines of the error message:
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
So how could this be done/fixed?
EDIT: I could not see how the attached link solves my problem. Apparently, it looks that, due to the error messages, however, there is some problem in the way I am trying to compile it statically. I could not find the right way to do so. I think the error message is missleading - It just ends with these lines (where these lines are less than one percent of the all message). Anyone who has done it can better answer. If you think your answer is more than just an educated guess, i would request you to please give it a try before answering. It will only take a couple minutes if you follow the attached link. Moreover, I have tagged C
also because it is same for C language programs as well.
Usually when you statically link a library (instead of linking it dynamically), you need to also link all of its dependencies manually. You need to figure out what library (dependency) it lacks and link it too.
Quick googling shows that inflateReset
is from a library called zlib
. Thus you need to link it using -lz
. There is a good chance you already have this library in your compiler search directories, but if you don't, then you need to compile it manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With