使用 CMake 为 iOS 编译 [英] Compiling for iOS with CMake
问题描述
我使用 CMake 作为我的构建工具编译了一个 C++ 静态库,我想将它链接到我的 iOS 应用程序.
我在 Xcode 中创建了一个简单的空"应用程序,并将名为 libengine.a 的库链接到它.
我试图编译我的 iOS 项目,但链接器给了我这个警告:
I've compiled a C++ static library by using CMake as my building tool and I want to link it to my iOS app.
I created a simple 'Empty' application in Xcode and linked my library called libengine.a to it.
I tried to compile my iOS project and the linker gave me this warning:
ignoring file /Users/.../build/engine/libengine.a,
file was built for archive which is not the architecture being linked (i386):
/Users/.../build/engine/libengine.a
据我所知,我需要为 ARM 处理器编译我的库.问题是我不知道怎么做.
我认为 CMake 确实缺乏好的教程.
无论如何,我的 CMake 脚本附在下面.
任何帮助将不胜感激.
谢谢,塔尔.
这是我的主要 CMake 脚本:
As I understand it, I need to compile my library for ARM processors. The problem is I don't know how.
I think CMake really lacks good tutorials.
Anyways, my CMake scripts are attached below.
Any help would be greatly appreciated.
Thanks, Tal.
Here is my main CMake script:
cmake_minimum_required(VERSION 2.8)
project(movie-night)
if (DEFINED PLATFORM)
include(toolchains/ios.cmake)
endif()
add_definitions(-Wall)
set(DEBUG)
if (DEFINED DEBUG)
add_definitions(-g)
endif()
if (DEFINED RELEASE)
add_definitions(-O3)
endif()
add_subdirectory(engine)
add_subdirectory(ui)
add_subdirectory(test)
这是我的工具链/ios.cmake 文件:
Here is my toolchains/ios.cmake file:
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR arm)
推荐答案
只需使用这个工具链文件:http://code.google.com/p/ios-cmake/ 并将其用作
Just use this toolchain file: http://code.google.com/p/ios-cmake/ and use it as
cmake -DCMAKE_TOOLCHAIN_FILE=path_to_your_toolchain_file
然后,在CMakeLists.txt
中:
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch armv7")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch armv7")
这篇关于使用 CMake 为 iOS 编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!