解决CMake交叉编译iOS版本时architecture not supported的错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Piao_Polar/article/details/78432749

最近在引入一个内部库,使用CMake编译成各个平台的版本,以便于移动平台使用。

关于CMake的配置方式,可以参考
http://blog.csdn.net/ktigerhero3/article/details/70313350

关于交叉编译,主要参考
http://blog.codingcoder.com/_book/1%20Tech/2017-10-20-Unity-crossplatform-plugins-with-cmake.html

在Windows/Mac/Android平台都成功编译后,在iOS版本编译的时候遇到了形如以下的错误:

cdefs.h:761:2: error: Unsupported architecture
_types.h:34:2: error: architecture not supported
_types.h:55:9: error: unknown type name ‘__int64_t’; did you mean ‘__int128_t’?

于是google关键词 “cdefs.h:761:2: error: Unsupported architecture” ,stackoverflow上一个看起来比较靠谱的回答提到是编译flag的问题
https://stackoverflow.com/questions/5334095/cmake-multiarchitecture-compilation

于是我看了下中间cmake生成的flags.make文件,果然在C_FLAG/CXX_FLAG中都没有-arch参数

既然知道了这个问题,就可以找相应的解决方案了,google “cmake specify the architecture iOS”,依照这里的回答:https://stackoverflow.com/questions/12630970/compiling-for-ios-with-cmake

在CMakeLists.txt或iOS.make中加入

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch armv7 -arch arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch armv7 -arch arm64")

编译就正常了

猜你喜欢

转载自blog.csdn.net/Piao_Polar/article/details/78432749