我该如何解决出现在Objective-C链接错误++而不是Objective-C的? [英] How do I resolve link errors that appear in Objective-C++ but not Objective-C?

查看:122
本文介绍了我该如何解决出现在Objective-C链接错误++而不是Objective-C的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从.M转换我的应用程序委托文件.mm(Objective-C的到的Objective-C ++),这样我可以访问用Objective-C ++第三方库。在Objective-C,我的应用程序委托建造和运行正常。但是,当我改变扩展,生成项目,我得到链接错误,所有这些都缺少C语言编写的,我用从静态库的符号。这些错误是典型的链接错误,格式如下:

I'm converting my App Delegate file from .m to .mm (Objective-C to Objective-C++) so that I can access a third-party library written in Objective-C++. In Objective-C, my app delegate builds and runs fine. But when I change the extension, the project builds and I get link errors, all of which are missing symbols from a static library written in C that I use. The errors are classic link errors with the following format:

MyFunction的(参数),从引用的:

"MyFunction(arguments)", referenced from:

- [MyAppDelegate myMethod的在MyAppDelegate.o

-[MyAppDelegate myMethod] in MyAppDelegate.o

图形符号未找到

所有的问题在应用程序的委托对象。我知道,我都设置为目标编译-C ++,因为我的ViewController文件为.mm。所以我的问题有几个部分了。

All of the problems are in the app delegate object. I know that I'm all set to compile Objective-C++ because my ViewController file is .mm. So my question has a few parts to it.

首先,是这些符号在某种意义上确实不存在,我不能使用它们?换句话说,是不是可以从一个Objective-C ++文件访问普通的旧的C函数?如果这是真的,这是pretty不幸。我认为,几乎所有的Objective-C code,当然所有的Objective-C code,至少建立为.mm,是有效的Objective-C ++。难道我错了吗?

First, are these symbols truly not there in the sense that I can't use them? In other words, is it not possible to access plain old C functions from an Objective-C++ file? If this is true, that's pretty unfortunate. I thought that almost all Objective-C code, and certainly all Objective-C code that at least builds as .mm, was valid Objective-C++. Am I wrong?

如果没有任何想法,我怎么能prevent这些错误?是否有在目标-C ++,我不知道不同的头的规则?

If not, any idea how I can prevent these errors? Are there header rules that are different in Objective-C++ that I don't know about?

感谢您的任何和所有帮助。

Thanks for any and all help.

推荐答案

混合C ++ / C或C ++ / Objective-C程序链接错误通常是由于C ++名字改编。请确保您有的externC连接到所有适当的声明,还以为所有的code的认同上的联系。也就是说,确保该函数的定义以及它被使用都可以看到的externC的extern的地方C ++

Link errors with mixed C++/C or C++/Objective-C programs are usually due to C++ name mangling. Make sure you have extern "C" attached to all the appropriate declarations, and also that all of your code agrees on the linkage. That is, make sure that the function definition as well as the places where it is used can all see the extern "C" or extern "C++".

在您的特定情况下,它看起来像 MyFunction的()是越来越用C ++链接并且其名称错位编译,但是,你的 myMethod的 Objective-C的文件,试图对重整的名字联系起来。

In your particular situation, it looks like MyFunction() is getting compiled with C++ linkage and having its name mangled, but that your myMethod Objective-C file is trying to link against the unmangled name.

下面是维基百科的文章了解名称重整的链接。

Here is a link to the wikipedia article about name mangling.

这篇关于我该如何解决出现在Objective-C链接错误++而不是Objective-C的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆