Discussion:
[CMake] Cross-compiling on OS X/x86 for Linux/ARM, linking a library
Vladimir Lebedev-Schmidthof
2009-10-19 18:07:52 UTC
Permalink
Hello everyone,

Two compiling platforms - Linux and OS X.
Same project, same cmake (2.6.4), same target (Linux/ARM).

Sources compiles well (GNU C/C++) but linking is different.

Everything is fine on Linux.

comparing make VERBOSE=1 outputs:

OS X: [path-to]/gcc -march=armv5te -mtune=xscale -msoft-float -fpic -
mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector
-fno-short-enums -dynamiclib -nostdlib -Wl,-shared,-Bsymbolic -Wl,-
rpath-link=[path-to]/usr/lib -Wl,--whole-archive -Wl,--no-undefined -
Wl,-rpath-link=[path-to]/usr/lib -o libmylib.so -install_name /Users/
dair/Project/native/libmylib.so [source-files]

Linux: [path-to]/gcc -fPIC -march=armv5te -mtune=xscale -msoft-float -
fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-
protector -fno-short-enums -nostdlib -Wl,-shared,-Bsymbolic -Wl,-rpath-
link=[path-to]/usr/lib -Wl,--whole-archive -Wl,--no-undefined -Wl,-
rpath-link=[path-to]/usr/lib -shared -Wl,-soname,libmylib.so -o
libmylib.so [source-files]

The problem is "-install_name" option. Cmake generates that in OS X
but GCC cross-compiler does not accept that. I can successfully link
the library (manually) by removing this option.

I set CMAKE_SYSTEM to Linux, even added "SET(APPLE 0)" but
install_name option is still generating.

Also, on OS X Cmake generates CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS as "-
dynamiclib -headerpad_max_install_names" which I don't need (-
headerpad_max_install_names is not recognized by my compiler) but I
can obviously set that property to what I need.

Please advise.

--
Thanks in advance,
Vladimir
Alexander Neundorf
2009-10-19 19:18:55 UTC
Permalink
Post by Vladimir Lebedev-Schmidthof
Hello everyone,
Two compiling platforms - Linux and OS X.
Same project, same cmake (2.6.4), same target (Linux/ARM).
Sources compiles well (GNU C/C++) but linking is different.
Everything is fine on Linux.
OS X: [path-to]/gcc -march=armv5te -mtune=xscale -msoft-float -fpic -
mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector
-fno-short-enums -dynamiclib -nostdlib -Wl,-shared,-Bsymbolic -Wl,-
rpath-link=[path-to]/usr/lib -Wl,--whole-archive -Wl,--no-undefined -
Wl,-rpath-link=[path-to]/usr/lib -o libmylib.so -install_name /Users/
dair/Project/native/libmylib.so [source-files]
Linux: [path-to]/gcc -fPIC -march=armv5te -mtune=xscale -msoft-float -
fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-
protector -fno-short-enums -nostdlib -Wl,-shared,-Bsymbolic -Wl,-rpath-
link=[path-to]/usr/lib -Wl,--whole-archive -Wl,--no-undefined -Wl,-
rpath-link=[path-to]/usr/lib -shared -Wl,-soname,libmylib.so -o
libmylib.so [source-files]
The problem is "-install_name" option. Cmake generates that in OS X
but GCC cross-compiler does not accept that. I can successfully link
the library (manually) by removing this option.
I set CMAKE_SYSTEM to Linux, even added "SET(APPLE 0)" but
install_name option is still generating.
You should set "CMAKE_SYSTEM_NAME", not "CMAKE_SYSTEM" to "Linux". If you
really set CMAKE_SYSTEM instead of CMAKE_SYSTEM_NAME, this will fix your
problem (after a quick look it seems install_name is really only set in the
Modules/Platform/Darwin*.cmake files, which should not get loaded if
CMAKE_SYSTEM_NAME is set to Linux).

Alex
Vladimir Lebedev-Schmidthof
2009-10-20 11:11:20 UTC
Permalink
Hello Alexander,
Post by Alexander Neundorf
Post by Vladimir Lebedev-Schmidthof
I set CMAKE_SYSTEM to Linux, even added "SET(APPLE 0)" but
install_name option is still generating.
You should set "CMAKE_SYSTEM_NAME", not "CMAKE_SYSTEM" to "Linux". If you
really set CMAKE_SYSTEM instead of CMAKE_SYSTEM_NAME, this will fix your
problem (after a quick look it seems install_name is really only set in the
Modules/Platform/Darwin*.cmake files, which should not get loaded if
CMAKE_SYSTEM_NAME is set to Linux).
I tried. Setting CMAKE_SYSTEM_NAME to "Linux" does not seem to affect
CMAKE_SYSTEM
(i.e. adding

-----
SET(CMAKE_SYSTEM_NAME "Linux")

...

MESSAGE("CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
MESSAGE("CMAKE_SYSTEM is ${CMAKE_SYSTEM}")
-----


results to

-----
CMAKE_SYSTEM_NAME is Linux
CMAKE_SYSTEM is Darwin-9.8.0
-----

Though

-----
SET(CMAKE_SYSTEM "Linux")
-----

results to

CMAKE_SYSTEM_NAME is Darwin
CMAKE_SYSTEM is Linux


So it seems that I have to set to Linux both variables. Anyway, cmake
keeps adding install_name (and other Darwin-specific things) to linker
options.
Hendrik Sattler
2009-10-20 11:56:46 UTC
Permalink
Post by Vladimir Lebedev-Schmidthof
Post by Vladimir Lebedev-Schmidthof
I set CMAKE_SYSTEM to Linux, even added "SET(APPLE 0)" but
install_name option is still generating.
You should set "CMAKE_SYSTEM_NAME", not "CMAKE_SYSTEM" to "Linux". If you
really set CMAKE_SYSTEM instead of CMAKE_SYSTEM_NAME, this will fix your
problem (after a quick look it seems install_name is really only set in the
Modules/Platform/Darwin*.cmake files, which should not get loaded if
CMAKE_SYSTEM_NAME is set to Linux).
I tried. Setting CMAKE_SYSTEM_NAME to "Linux" does not seem to affect
CMAKE_SYSTEM
WHERE are you try to set this? Setting this in a CMakeLists.txt file
will not work. Did you read the wiki page[1] about cross-compiling?
Check that CMAKE_CROSSCOMPILING is set to true.

HS

[1]: http://www.cmake.org/Wiki/CMake_Cross_Compiling
Vladimir Lebedev-Schmidthof
2009-10-20 12:51:11 UTC
Permalink
Hello Hendrik,
Post by Vladimir Lebedev-Schmidthof
Post by Vladimir Lebedev-Schmidthof
I tried. Setting CMAKE_SYSTEM_NAME to "Linux" does not seem to
affect
Post by Vladimir Lebedev-Schmidthof
CMAKE_SYSTEM
WHERE are you try to set this? Setting this in a CMakeLists.txt file
will not work. Did you read the wiki page[1] about cross-compiling?
Check that CMAKE_CROSSCOMPILING is set to true.
HS
[1]: http://www.cmake.org/Wiki/CMake_Cross_Compiling
Thanks, I've read that before posting my first post :-)

I tried having toochain.cmake file in the same dir as CMakeLists.txt

using
cmake -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake .

does not seem to even read that file. I tried to state full path, move
the file away, no luck.

So I just include()d my toolchain.cmake in CMakeLists.txt.

And, yes, CMAKE_CROSSCOMPILING is set to false.

I tried to set it to true but it has no effect.

By the way, on Linux host CMAKE_TOOLCHAIN_FILE variable doesn't have
effect as well.

--
Sincerely Yours,
Vladimir Lebedev-Schmidthof
Hendrik Sattler
2009-10-20 13:50:06 UTC
Permalink
Post by Vladimir Lebedev-Schmidthof
I tried having toochain.cmake file in the same dir as CMakeLists.txt
using
cmake -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake .
does not seem to even read that file. I tried to state full path, move
the file away, no luck.
Since you are doing an in-source build: did you make sure prior to
issuing the above command that you cleaned the source directory from
all cmake-generated files from previous runs (especially removing any
CMakeCache.txt files)?

HS
Vladimir Lebedev-Schmidthof
2009-10-20 14:18:47 UTC
Permalink
Hello Hendrik,
Post by Hendrik Sattler
Post by Vladimir Lebedev-Schmidthof
I tried having toochain.cmake file in the same dir as CMakeLists.txt
using
cmake -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake .
does not seem to even read that file. I tried to state full path,
move
Post by Vladimir Lebedev-Schmidthof
the file away, no luck.
Since you are doing an in-source build: did you make sure prior to
issuing the above command that you cleaned the source directory from
all cmake-generated files from previous runs (especially removing any
CMakeCache.txt files)?
No I didn't. I just did and all compiled and linked successfully.

Sorry for stupid questions then, I will remember to clean cmake-
generated files in future.

Thank you very much.

--
Sincerely Yours,
Vladimir Lebedev-Schmidthof
Bill Hoffman
2009-10-20 14:35:04 UTC
Permalink
Post by Vladimir Lebedev-Schmidthof
No I didn't. I just did and all compiled and linked successfully.
Sorry for stupid questions then, I will remember to clean
cmake-generated files in future.
Thank you very much.
--
You should use out of source builds in the future... :)

-Bill

Loading...