How do I statically link iconv on windows using msys?
Asked Answered
P

1

6

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)

Pub answered 30/11, 2012 at 21:16 Comment(0)
B
3

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

Belief answered 1/1, 2013 at 17:3 Comment(2)
Presumably the first two will link everything statically, whereas the third only links iconv statically (and other libraries like zlib will still link to the dll).Pub
Or -Wl,-Bstatic,-liconvVitiligo

© 2022 - 2024 — McMap. All rights reserved.