[CMake] Recommended Multilib Build Approach?

Xavier Besseron xavier.besseron at uni.lu
Mon Jul 30 17:28:47 EDT 2012


On Mon, Jul 30, 2012 at 9:44 PM, Alexander Neundorf
<a.neundorf-work at gmx.net> wrote:
> On Monday 30 July 2012, Xavier Besseron wrote:
>> To build i386 binaries on my 64-bit system with multilib, I just do
>> something like this:
>>
>> mkdir build-i386
>> cd build-i386
>> CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-melf_i386" cmake ../src/
>>
>> And to build x86-64 binaries on my 64-bit system, I don't need to
>> specify anything since it is the default behavior.
>
> Is this maybe somewhat similar to the fat binaries on OSX ?


No, I don't think so. You have to use two build directories, one for
32-bit code, one for 64-bit code. At the end, you will have two
different binaries.


> How is this handled by CMake ?


This is quite independent of CMake. It works with other build systems
like autotools/makefile as well.

CFLAGS="-m32" CXXFLAGS="-m32" tells CMake to pass the '-m32' to the C
and C++ compilers.
It tells the compiler to generate code that runs on any i386 system
(cf gcc manpage).

LDFLAGS="-melf_i386" tells CMake to pass the '-melf_i386' to the linker.
It tells the linker to use the i386 ELF format for the binary (cf ld manpage).

This works for GNU compiler/linker at least. I haven't tried other compilers.


Xavier


More information about the CMake mailing list