[CMake] Cross-compiling, CMAKE_C_FLAGS, and configure-time compiler tests
Justin Holewinski
justin.holewinski at gmail.com
Mon Dec 13 10:49:40 EST 2010
I am experiencing a cross-compiling issue that I believe is related to how
toolchain files interact with the configure-time compiler checks. For
reference, I am targeting the iOS 4.2 SDK. I have a toolchain file that
sets CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, CMAKE_C_LINK_FLAGS, and
CMAKE_CXX_LINK_FLAGS with appropriate flags for the iOS platform, in
particular "-arch armv6 -arch armv7". The toolchain file also sets the
proper C and C++ compilers.
When CMake is executed and the C compiler is tested, the toolchain-specified
compiler arguments are passed to the link line, but *not* the compile line
(according to the error output). Since the compile line does not contain
the "-arch" arguments, the generated object file is for i386. However,
since the link line contains these flags, the linker tries to link ARM code
and fails.
Are there any additional variables I should be setting in addition to
CMAKE_C_FLAGS and CMAKE_CXX_FLAGS in order to get the compiler tests to use
the right flags? If I add the "-arch" flags using ADD_DEFINITIONS(), they
are passed to the compiler test and it succeeds. That seems like a hack and
not a proper solution, though.
Below is the CMake output that prints the values of CMAKE_*_FLAGS as set by
the toolchain file, as well as the compile and link lines used by CMake.
I am using CMake 2.8.3 on Snow Leopard 10.6.5.
CMake Output:
-- CMAKE_C_FLAGS: -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_CXX_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_C_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_CXX_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_C_FLAGS: -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_CXX_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_C_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- CMAKE_CXX_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2
-- Check for working C compiler:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -- broken
CMake Error at
/opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler
"/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2" is not
able to compile a simple test program.
It fails with the following output:
Change Dir:
/Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make
CMakeFiles/cmTryCompileExec.dir/build
/opt/local/bin/cmake -E cmake_progress_report
/Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/CMakeFiles
1
Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2
-I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include
-o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -c
/Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec
/opt/local/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch
armv6 -arch armv7 -pipe -no-cpp-precomp
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-miphoneos-version-min=4.2
CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -o cmTryCompileExec
-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib
ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file
was built for i386 which is not the architecture being linked (armv6)
Undefined symbols for architecture armv6:
"_main", referenced from:
start in crt1.3.1.o
ld: symbol(s) not found for architecture armv6
collect2: ld returned 1 exit status
ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file
was built for i386 which is not the architecture being linked (armv7)
Undefined symbols for architecture armv7:
"_main", referenced from:
start in crt1.3.1.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
lipo: can't open input file:
/var/folders/pS/pSWOJvZ-FDS4A2Eo7TwIzE+++TI/-Tmp-//ccKkL4CZ.out (No such
file or directory)
make[1]: *** [cmTryCompileExec] Error 1
make: *** [cmTryCompileExec/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:30 (project)
-- Configuring incomplete, errors occurred!
--
Thanks,
Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101213/2ae74fd1/attachment-0001.htm>
More information about the CMake
mailing list