Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I statically link iconv on windows using msys?

Tags:

mingw

msys

iconv

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)

like image 891
Paul Moore Avatar asked Nov 30 '12 21:11

Paul Moore


1 Answers

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

like image 149
Zombo Avatar answered Jan 04 '23 07:01

Zombo