【发布时间】:2018-04-08 07:38:38
【问题描述】:
我最近尝试将 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)
我尝试了互联网上的所有解决方案,但它们都不适合我,我也尝试过共享库,但这也不起作用。
【问题讨论】:
标签: c++ ios xcode cmake linker