Xcode/IOS: linking a CMake library
Xcode/IOS: linking a CMake library
我最近尝试将一个C++的"CMake"项目链接到现有的IOS项目,我能够使用Project > Build Setting > Header Search Path
将标头包含在Xcode中,并将libxeuus.a
添加到构建阶段,但是突然当我想在我的lib中使用方法Xcode时,会引发一个错误,描述为:
clang: warning: libstdc++ is deprecated; move to libc++ [-Wdeprecated] Undefined symbols for architecture x86_64:
"hello()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
但我检查了我的库架构lipo
它似乎还可以。
>> lipo -i libxeuus.a
input file libxeuus.a is not a fat file
Non-fat file: libxeuus.a is architecture: x86_64
这是我main.mm
文件:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <xeuus.h>
int main(int argc, char * argv[]) {
hello();
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
这是我的headers/xeuus.h
#ifndef xeuus_h
#define xeuus_h
#include "test.h"
#endif
这是我的headers/test.h
#ifndef test_h
#define test_h
#include <iostream>
#include <string>
int hello();
#endif
这是sources/test.cpp
:
#include "test.h"
int hello() {
auto x = 0;
// check if c++11 working
auto p = std::make_shared<int>(2);
return 10;
}
和CMakeLists.txt
:
cmake_minimum_required(VERSION 3.0)
set(PROJECT_NAME xeuus)
set(PROJECT_VERSION 1.0.1)
set(PROJECT_DESCRIPTION "A lib to be shared.")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_BUILD_TYPE Release)
set(XEUUS_HEADERS_DIR ./headers)
set(XEUUS_SOURCES_DIR ./sources)
include_directories(${XEUUS_HEADERS_DIR})
file(GLOB_RECURSE SOURCE_FILES
${XEUUS_SOURCES_DIR}/*.cpp
)
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
我尝试了互联网上的所有解决方案,它们都不适合我,我也尝试了共享库,但这也不起作用。
通过在CMakeLists中定义IOS平台来修复.txt并使用CMake编译项目,然后将其添加到主项目中。
set (CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk")
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用CMake创建QML插件
- cmake如何在fedora工作站中找到boost静态库包
- 使用CMake检测支持的C++标准
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- cmake在我的项目中所需的所有静态库都不成功
- Boost Graph Library,修复节点大小
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 无法链接 CMake 中的本地库
- CMake:尝试在 Jenkins 构建机器上运行时出现"Linked Library"错误 (0xc0000135)
- 将 c++ cmake-library 构建发布到本地存储库时出现 Gradle 错误
- Xcode/IOS: linking a CMake library
- CMake add library libpq (postgreSQL) mac c++ clion
- CMake & dyld: Library not loaded: @rpath/libLTO.dylib
- CMAKE带有Boost Library Windows 10库未正确找到
- CMake link a library (.a/.so)
- Cmake external library .a