Discussion:
[CMake] how to compile as 32bit on a 64bit Linux host ?
Martin Koller
2013-02-15 10:46:40 UTC
Permalink
Hi all,

for the question above I found different answers on the web, so I'm puzzled
and wanted to know an authoritative answer from the cmake gurus.

What I found:
http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains
=> "On mixed 32/64 bit Linux installations cross compilation cannot be used to build for 32/64 bit only."

but also:

http://stackoverflow.com/questions/4131158/how-to-cross-compile-for-linux-x86-with-linux-amd64-cmake-and-g
=> talking about using a toolchain file ...

so please tell me: what is the correct way or is there no way ?
--
Best Regards/Schöne Grüße

Martin Koller

-----------------------------------------------------------------
Ing. Martin Koller , mailto:***@etm.at , http://www.etm.at
ETM professional control GmbH, A Siemens Company
Phone:+43 2682/741-62603, Fax:+43 2682/741-52555
A-7000 Eisenstadt Marktstr. 3, VAT: ATU 61342924, DVR 4000597
Register Number: FN 256655i at: Commercial Court Eisenstadt
-----------------------------------------------------------------
Ansis Māliņš
2013-02-15 10:58:37 UTC
Permalink
The *easiest* way is to use a virtual machine.
m.hergarden
2013-02-15 11:11:27 UTC
Permalink
Can you share a bit more context? I suspect there may be no single
correct answer, as it depends on your situation what the best way is. If
you are using a toolchain file you will have to put the decision of
using that file outside of your cmake file. You can also opt to put a
check inside your cmake file and set compiler flags (-m32 / -m64)
accordingly.
Using a toolchain file is more flexible when releasing a project, but
autoconfiguring is nice when running builds on buildservers through
ctest scripts.

Regards,
Micha
Post by Martin Koller
Hi all,
for the question above I found different answers on the web, so I'm puzzled
and wanted to know an authoritative answer from the cmake gurus.
http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains
=> "On mixed 32/64 bit Linux installations cross compilation cannot be used to build for 32/64 bit only."
http://stackoverflow.com/questions/4131158/how-to-cross-compile-for-linux-x86-with-linux-amd64-cmake-and-g
=> talking about using a toolchain file ...
so please tell me: what is the correct way or is there no way ?
Martin Koller
2013-02-15 14:41:59 UTC
Permalink
Post by m.hergarden
Can you share a bit more context? I suspect there may be no single
correct answer, as it depends on your situation what the best way is.
I have a 64bit Linux server (RHEL5), which automatically builds our software every night
(triggered via a Jenkins job - but that really shouldn't matter).
I'd like to use this server to first build the software for 32bit platforms
and then for 64bit platforms. Our customers should be able to choose their
runtime system being 32 or 64 bit)
Post by m.hergarden
If you are using a toolchain file you will have to put the decision of
using that file outside of your cmake file.
yes, that would be sufficient.
I'm just not sure if it is enough to change the compiler flags or if
there is more to change (paths etc.)
Post by m.hergarden
Post by Martin Koller
http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains
=> "On mixed 32/64 bit Linux installations cross compilation cannot be used to build for 32/64 bit only."
is it wrong or outdated ?
Post by m.hergarden
You can also opt to put a
check inside your cmake file and set compiler flags (-m32 / -m64)
accordingly.
Using a toolchain file is more flexible when releasing a project, but
autoconfiguring is nice when running builds on buildservers through
ctest scripts.
Regards,
Micha
Post by Martin Koller
Hi all,
for the question above I found different answers on the web, so I'm puzzled
and wanted to know an authoritative answer from the cmake gurus.
http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains
=> "On mixed 32/64 bit Linux installations cross compilation cannot be used to build for 32/64 bit only."
http://stackoverflow.com/questions/4131158/how-to-cross-compile-for-linux-x86-with-linux-amd64-cmake-and-g
=> talking about using a toolchain file ...
so please tell me: what is the correct way or is there no way ?
--
Best regards/Schöne Grüße

Martin

A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?

() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments

This mail was not scanned before sending.
It was sent from a secure Linux desktop.
Yngve Inntjore Levinsen
2013-02-15 15:26:39 UTC
Permalink
Hello,
Post by Martin Koller
I'm just not sure if it is enough to change the compiler flags or if
there is more to change (paths etc.)
This is why I prefer toolchain files over adding an option inside the
CMakeLists.txt files. On some systems you probably also want to change
the search path for libraries in particular (often /usr/lib32 instead of
/usr/lib), so that the find_package() commands and similar does not find
the incompatible 64 bit libraries.

In our system we both have an option to "force 32 bit" (which basically
just adds -m32 to compile flags), and I have a toolchain file (which
corresponds to my stackoverflow answer). I find the toolchain file to be
more accurate/flexible to get correct setup.

In addition to the three lines you might also want to set paths (I do
not need that on my system for my projects), something along the lines of:

set(CMAKE_FIND_ROOT_PATH /usr/lib32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Cheers,
Yngve
c***@elemtech.com
2013-02-15 15:33:31 UTC
Permalink
Or simply specify -m32 at the first configure
CFLAGS=-m32 CXXFLAGS=-m32 cmake ../src

find_library() works correctly if you do that, and it automatically detects if the 32 bit libraries are in /usr/lib32 or /usr/lib.

Clint

----- Original Message -----
Post by Yngve Inntjore Levinsen
Hello,
Post by Martin Koller
I'm just not sure if it is enough to change the compiler flags or if
there is more to change (paths etc.)
This is why I prefer toolchain files over adding an option inside the
CMakeLists.txt files. On some systems you probably also want to change
the search path for libraries in particular (often /usr/lib32 instead of
/usr/lib), so that the find_package() commands and similar does not find
the incompatible 64 bit libraries.
In our system we both have an option to "force 32 bit" (which basically
just adds -m32 to compile flags), and I have a toolchain file (which
corresponds to my stackoverflow answer). I find the toolchain file to be
more accurate/flexible to get correct setup.
In addition to the three lines you might also want to set paths (I do
set(CMAKE_FIND_ROOT_PATH /usr/lib32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Cheers,
Yngve
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.cmake.org/Wiki/CMake_FAQ
http://www.cmake.org/mailman/listinfo/cmake
Yngve Inntjore Levinsen
2013-02-15 16:22:14 UTC
Permalink
It is true, I actually never had problems just adding -m32 on my
machines, but I assumed some systems are more difficult than others..
But what do I know? :)

Cheers,
Yngve
Post by c***@elemtech.com
Or simply specify -m32 at the first configure
CFLAGS=-m32 CXXFLAGS=-m32 cmake ../src
find_library() works correctly if you do that, and it automatically detects if the 32 bit libraries are in /usr/lib32 or /usr/lib.
Clint
Keith Gardner
2013-02-15 15:29:24 UTC
Permalink
What I have done in the past is the -m32 flag to the CMAKE_CXX_FLAGS and all of the search paths were updated automatically. You just need to add the flag when you CMake for the first time. I did this on CentOS 5.8 x64 without any problems.

Keith

-----Original Message-----
From: cmake-***@cmake.org [mailto:cmake-***@cmake.org] On Behalf Of Yngve Inntjore Levinsen
Sent: Friday, February 15, 2013 9:27 AM
To: ***@cmake.org
Subject: Re: [CMake] how to compile as 32bit on a 64bit Linux host ?

Hello,
Post by Martin Koller
I'm just not sure if it is enough to change the compiler flags or if
there is more to change (paths etc.)
This is why I prefer toolchain files over adding an option inside the CMakeLists.txt files. On some systems you probably also want to change the search path for libraries in particular (often /usr/lib32 instead of /usr/lib), so that the find_package() commands and similar does not find the incompatible 64 bit libraries.

In our system we both have an option to "force 32 bit" (which basically just adds -m32 to compile flags), and I have a toolchain file (which corresponds to my stackoverflow answer). I find the toolchain file to be more accurate/flexible to get correct setup.

In addition to the three lines you might also want to set paths (I do not need that on my system for my projects), something along the lines of:

set(CMAKE_FIND_ROOT_PATH /usr/lib32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Cheers,
Yngve
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Martin Koller
2013-02-19 15:46:19 UTC
Permalink
Post by Yngve Inntjore Levinsen
Hello,
Post by Martin Koller
I'm just not sure if it is enough to change the compiler flags or if
there is more to change (paths etc.)
I now found out that - for me - it's not enough to simply add the -m32 flags,
as our cmake files check ${CMAKE_SYSTEM_PROCESSOR} for various things, so
I need to use a toolchain file where I set this.
This also leads to the cmake var CMAKE_CROSSCOMPILING being set.

But what I now discovered is a problem with generated targets:
E.g. one subdir builds a tool which is used in another subdir to create
intermediate files.
That is:
add_executable(tool ...)
and the other dir uses it
add_custom_command(OUTPUT dbwork.h
COMMAND tool ...)

What I see is that cmake no longer finds the created tool.

When cross-compiling for e.g. the ARM CPU, I use export/import cmake files,
but this is not needed here as an i686 executable can run on an x86_64 CPU.

What do I have to give cmake so that it still finds the tool ?
--
Best regards/Schöne Grüße

Martin

A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?

() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments

This mail was not scanned before sending.
It was sent from a secure Linux desktop.
Loading...