I am using mingw gcc and msys to build a number of GNU utilities. In the past, I have had a lot of problems caused by different executables requiring different versions of libiconv, so to avoid the issue I wanted to link iconv statically into the executables.
I have built libiconv using mingw and msys with configure --enable-static. This creates both the DLL, the .dll.a import library and the plain .a static library.
However, when I try to build another program which links with a simple -liconv, I get the DLL linked in. I assume that ld is for some reason preferring the import library over the static library (not a bad choice in general, this is a special case).
How can I ensure that programs I build are statically linked? One obvious approach is simply to remove the .dll.a file while doing the build. That is probably the simplest option, but I am curious - is there a linker flag I can set (via something like LDFLAGS) to force iconv to be loaded statically (ideally, without affecting other libraries, but at a pinch I'd be OK with loading all libraries statically)
You are right, by default it is going to link "shared" unless you tell it specifically to link static. You can do this a few ways, whichever works for you
make CC='gcc -static'
make LDFLAGS=-static
make LDFLAGS=libiconv.a
You just need to look at the Makefile
and find the least intrusive way to fit it in.
Example
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