使用cmakelist 来迁移
准备工作:
1、mac一台
2、cmake 安装 cmake使用, [cmake下载] (cmake.org/download/) 3、xcode 安装好
cmakelist 文件代码:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project(recognizersdk C CXX)
set(CMAKE_CXX_STANDARD 14)
MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )
# 工程名
set(PROJECT_NAME xxxsdk)
set(SRC_FILES
Testcpp.cpp
)
include_directories(
./include
./include/c_api
./include/cxx_api
)
# 编译时链接路径 此处对不同架构时的链接路径做了一些处理(如果不需要链接其他库可以注释掉)
if(${ARCHS} STREQUAL "arm64")
set(LIB_DIR ios_arm64_r)
elseif(${ARCHS} STREQUAL "armv7")
set(LIB_DIR ios_armv7_r)
elseif(${ARCHS} STREQUAL "armv7s")
set(LIB_DIR ios_armv7s_r)
elseif(${ARCHS} STREQUAL "i386")
set(LIB_DIR ios_i386_r)
elseif(${ARCHS} STREQUAL "x86_64")
set(LIB_DIR ios_x86_64_r)
endif()
link_directories($ENV{DROOT}/bin/${LIB_DIR})
# 生成目标 STATIC和ARCHIVE对应静态库 SHARED和LIBRARY对应动态库
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})
link_directories(${CMAKE_SOURCE_DIR}/Xamarin.iOS)
# 链接/安装
target_link_libraries(${PROJECT_NAME} Microsoft.CognitiveServices.Speech.core)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
ios.toolchain.cmake 文件也要有哈,然后在执行:
cd example/example-lib
mkdir build
cd build
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64
cmake --build . --config Release
然后就能得到在iOS上使用的.a库了。