Cmake cross compile flags

依然范特西╮ 提交于 2020-01-14 06:06:10

问题


I writing toolchain.cmake file for Linaro toolchain.

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)

I run cmake:

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

But at compile time, i had error about exceptions, instead of defined compiler flags in toolchain file:

error: exception handling disabled, use -fexceptions to enable

As far as I can understand my CMAKE_C_FLAGS_RELEASE, CMAKE_CXX_FLAGS_RELEASE has no effect. Why?


回答1:


Problem solved, my mistake. I use set(CMAKE_CXX_FLAGS "<flags>") against set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}<flags>" in main project. I was confused, because this CMakeLists.txt works correctly for android-cmake and Google-NDK (instead of all android-cmake toolchain flags was rejected).



来源:https://stackoverflow.com/questions/11045314/cmake-cross-compile-flags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!