简体   繁体   English

在xcode 4.5.2中编译具有C ++ 11支持的混合Objective-C / C ++项目的链接错误

[英]Link errors compiling a mixed objective-C/C++ project with C++11 support in xcode 4.5.2

I am trying to compile a workspace of 3 projects with C++11 support. 我正在尝试编译具有C ++ 11支持的3个项目的工作区。 This set of projects has successfully compiled and linked using LLVM compiler defaults. 这组项目已使用LLVM编译器默认值成功编译和链接。 In addition, the c++ code has previously compiled on a number of compilers including g++, llvm, msvc, sun, irix etc so it is very clean code. 另外,C ++代码以前已经在许多编译器上进行了编译,包括g ++,llvm,msvc,sun,irix等,因此它是非常干净的代码。

Under the c++ language dialect section of the workspace build settings there are 3 line items: 在工作区构建设置的c ++语言方言部分下,有3个项目:

c language dialect C语言方言
c++ language dialect C ++语言方言
c++ standard library c ++标准库

Using the settings: 使用设置:

c language dialect: compiler default c语言方言:编译器默认
c++ language dialect: compiler default C ++语言方言:编译器默认
c++ standard library: libc++ (LLVM c++ standard library with c++11 support) c ++标准库:libc ++(具有c ++ 11支持的LLVM c ++标准库)

I can successfully compile but get many link errors. 我可以成功编译,但是出现许多链接错误。 Some are from our own functions and some are from standard functions. 有些来自我们自己的功能,有些来自标准功能。 Here is a sample of link errors to standard functions: 这是到标准函数的链接错误的示例:

(null): "std::string::find_last_of(char const*, unsigned long) const", referenced from: (null): "std::string::size() const", referenced from: (null):“ std :: string :: find_last_of(char const *,unsigned long)const”,引用自:(null):“ std :: string :: size()const”,引用自:

It seemed clear that I was linking to the wrong standard library, so I investigated changing various options above. 显然我链接到错误的标准库,因此我研究了更改上述各种选项的方法。 Changing the dialect to -std=c++11 even broke my compilation. 将方言更改为-std = c ++ 11甚至破坏了我的编译。 I could not find a combination that worked for me. 我找不到适合我的组合。

Can you suggest what might be wrong? 您能建议出什么问题吗?

EDIT: my motivation for doing this is that I want to use std::thread in my c++ code that interfaces with objective-c (and have that c++ code still be portable) 编辑:我这样做的动机是,我想在与Objective-C交互的C ++代码中使用std :: thread(并使c ++代码仍然可移植)

XCode 4.5.2 / OSX 10.8.2 XCode 4.5.2 / OSX 10.8.2

I've been getting these 我一直在得到这些

(null): "std::string::find_last_of(char const*, unsigned long) const", 
 referenced from: (null):    "std::string::size() const", referenced from:

Variously with different versions of openCV libraries. 不同版本的openCV库。 It seems like the issue is access to the C++ standard library. 看来问题出在访问C ++标准库。 In this case working settings were as follows: 在这种情况下,工作设置如下:

Older library versions: 较旧的库版本:

C Language Dialect GNU99[-std=gnu99]
C++ Language Dialect GNU++11[-std=gnu++11]
C++ Standard Library libstdc++ (GNU C++ standard library)

recent library versions: 最新的库版本:

C Language Dialect GNU99[-std=gnu99]
C++ Language Dialect GNU++11[-std=gnu++11]
C++ Standard Library libc++ (LLVM C++ standard library with C++11 support)

Toggling the standard library spec to either version yields those errors. 将标准库规范切换到任一版本都会产生这些错误。

I finally traced the problem to two things 我终于把问题归结为两件事

1) Despite the fact I set the compiler options at the workspace level, these options were not being propagated to the constituent projects. 1)尽管我在工作空间级别设置了编译器选项,但这些选项并未传播到组成项目中。 Something to be aware of! 有一点要注意! So in effect different projects were being compiled with different sets of compiler libraries and dialects - so not surprising there were link errors. 因此,实际上,不同的项目正在使用不同的编译器库和方言集进行编译-因此链接错误就不足为奇了。 The combination of options that worked for me were: 对我有用的选项组合是:

C Language Dialect Compiler Default C语言方言编译器默认
C++ Language Dialect -std=c++11 C ++语言方言 -std = c ++ 11
C++ Standard Library libc++ (LLVM C++ standard library with C++11 support) C ++标准库 libc ++(具有C ++ 11支持的LLVM C ++标准库)

2) Under c++11 compilation, one of my projects would not compile. 2)在c ++ 11编译下,我的一个项目无法编译。 After fixing the syntax error, it compiled and linked fine with the above options 修复语法错误后,它使用上述选项进行了编译和链接

While use Code 5 i had a similar problem 虽然使用代码5我有类似的问题

Undefined symbols for architecture armv7:
"std::string::clear()", referenced from:
FormatLog(unsigned int, int, char const*, std::string&) in libMO.a(AppLog.o)

Changing "Deployment Target" from 7.0 to 6.0 helped me. 将“部署目标”从7.0更改为6.0对我有所帮助。

For XCode 4.5 it seems have to use LLVM C++ with C++11 support compiler instead GNU C++ compiler for C++ Standard Library. 对于XCode 4.5,似乎必须使用LLVM C++ with C++11 support编译器的LLVM C++ with C++11 support而不是用于C ++标准库的GNU C++编译器。

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

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