Cmake交叉编译标志

时间:2012-06-15 05:55:55

标签: gcc cmake cross-compiling toolchain

我为Linaro工具链编写toolchain.cmake文件。

include(CMakeForceCompiler)
set(CMAKE_CROSSCOMPILING   TRUE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "armv7-a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-psabi -frtti -fexceptions" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wno-psabi -fexceptions" )
set(CMAKE_C_COMPILER /home/stranger/linaro/android-toolchain-eabi/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER /home/stranger/linaro/android-toolchain-eabi/bin/arm-linux-androideabi-g++)
CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" GNU)
CMAKE_FORCE_CXX_COMPILER("${CMAKE_CXX_COMPILER}" GNU)
set(CMAKE_FIND_ROOT_PATH  home/stranger/linaro/android-toolchain-eabi/arm-linux-androideabi)
include_directories( SYSTEM /home/stranger/android-ndk-r8/platforms/android-14/arch-arm/usr/include)
include_directories( SYSTEM /home/stranger/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include)
include_directories( SYSTEM /home/stranger/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include)

我运行cmake:

cmake -DBUILD_ANDROID=On -DCMAKE_TOOLCHAIN_FILE=<path to this toolchain.cmake>  -DCMAKE_BUILD_TYPE=Release <path to my cmake project>

但是在编译时,我有关于异常的错误,而不是工具链文件中定义的编译器标志:

error: exception handling disabled, use -fexceptions to enable

据我所知,我的CMAKE_C_FLAGS_RELEASE,CMAKE_CXX_FLAGS_RELEASE无效。为什么呢?

1 个答案:

答案 0 :(得分:2)

问题解决了,我的错误。我在主项目中对set(CMAKE_CXX_FLAGS "<flags>")使用set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}<flags>"。我很困惑,因为这个CMakeLists.txt适用于android-cmake和Google-NDK(而不是所有的android-cmake工具链标志被拒绝)。