14 February 2012

How to perfectly mix 32bit and 64bit libraries in MinGW

Assuming you have multilib (dual 32bit/64bit) GCC and you have common libraries in /usr/local you could put all 32bit and 64bit in /usr/local/lib folder altogether.

How? I found out that GCC filename lookup for libraries (be it import lib or static lib) have the following order:
In case of -l[foo] getting parsed:
1. lib[foo].dll.a
2. [foo].dll.a
3. lib[foo].a
4. [foo].lib

The common convention is (1) as import library and (3) as static library however this may varied among makefiles. If you're willing to do a little renaming work or better more edit the libtool or makefiles. You could arrange them this way:

32bit import lib: lib[foo].dll.a
32bit static lib: lib[foo].a
64bit import lib: [foo].dll.a
64bit static lib: [foo].lib

This way, during compile gcc will look for all possibilities till found the matched bitness with import lib having higher priority than static lib. Huh lucky number 4 eh?

Hence the same -L/usr/local/lib and -lfoo for both 32 and 64bit hence single .pc (pkg-config) file too. Nice!

I use this convention in my MinGW toolchain

No comments:

Post a Comment