[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Mingw-cross-env-list] Linking statically

From: Nikos Chantziaras
Subject: Re: [Mingw-cross-env-list] Linking statically
Date: Thu, 27 Jan 2011 07:28:36 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110126 Thunderbird/3.1.7

On 01/26/2011 03:23 PM, Daniel Stonier wrote:
On 26 January 2011 21:53, Mark Brand<address@hidden>  wrote:


i686-pc-mingw32-g++ -o dude.exe main.o -llog4cxx

This fails with undefined references everywhere. Now if I add in all
the underlying static libs, it works.

i686-pc-mingw32-g++ -o dude.exe main.o -llog4cxx -laprutil-1 -lapr-1
-lexpat -liconv -lrpcrt4 -lshell32 -lws2_32 -ladvapi32 -lkernel32 -lmsvcrt

No problem. My question is, wasn't libtool supposed to use the .la
files to automatically find and reference these underlying libs? Is
there a syntax to get it to do so?

I'm not a libtool expert, but don't you have to invoke libtool if you want
to use it?  I'm looking at


Yes, looks like it. I learned how to use it by hand for the first time
today and it does indeed resolve the problem linkages by referring to
the .la file.

Actually, you're supposed to use i686-pc-mingw32-pkg-config to get the compile as well as the build flags. If the main library you link against provides a pkg-config file, of course. If not, I guess you have to use libtool.

For example, to compile a program that uses the "foo" library you append the correct compiler flags with:

  i686-pc-mingw32-g++ [...] $(i686-pc-mingw32-pkg-config foo --cflags)

And for linking you replace "--cflags" with "--libs".

I'm also a bit curious as to why mingw cross-compiling toolchains
always use static archives instead of shared libraries?

That's simply because on Windows static linking is the norm. The advantages of dynamic linking disappear once you bundle the libraries with your program. To get something from dynamic linking, the libraries must exist system-wide so that all applications can use them simultaneously. But since that's not the case, there's no need to bother with dynamic linking anymore.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]