简体   繁体   English

Xcode / IOS:链接CMake库

[英]Xcode/IOS: linking a CMake library

I recently tried to link a C++ "CMake" project to an existing IOS project, I was able to include headers into Xcode using Project > Build Setting > Header Search Path , and also added libxeuus.a into build phase, but suddenly when I wanted to use method inside my lib Xcode raise an error with description of : 我最近尝试将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)

but I checked my library architecture with lipo it seems to be okay. 但是我用lipo检查了我的图书馆架构,看来还可以。

>> lipo -i libxeuus.a
input file libxeuus.a is not a fat file
Non-fat file: libxeuus.a is architecture: x86_64

Here is my main.mm file: 这是我的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]));
    }
}

here is my headers/xeuus.h 这是我的headers/xeuus.h

#ifndef xeuus_h
#define xeuus_h
#include "test.h"
#endif

here is my headers/test.h 这是我的headers/test.h

#ifndef test_h
#define test_h

#include <iostream>
#include <string>

int hello();

#endif

and here is sources/test.cpp : 这是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;
}

and CMakeLists.txt : 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)

I tried every solution on the internet non of them working for me, also I tried Shared library, but that doesn't work either. 我尝试了Internet上的所有解决方案,但没有一个对我有用,我也尝试了共享库,但这也不起作用。

通过在CMakeLists.txt中定义IOS平台并使用CMake编译项目,然后将其添加到主项目中来进行修复。

set (CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM