我应该如何让 Xcode 链接使用 C++ 静态库的 iOS 项目 [英] How should I get Xcode to link an iOS project that uses a C++ static library

查看:42
本文介绍了我应该如何让 Xcode 链接使用 C++ 静态库的 iOS 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Xcode,我编写了一个 Cocoa Touch 静态库,主要是用 C++ 编写的.它为了 Objective-C 客户端代码公开了一个 C 接口.

Using Xcode, I've written a Cocoa Touch static library, mainly in C++. It exposes a C interface for the benefit of Objective-C client code.

我有一个使用它的客户端 iOS 应用程序,一切正常运行,除了我发现我需要在客户端项目中包含一个最小的 .cpp 文件以获取到成功.否则我会得到与 C++ 相关的未解析符号,例如operator new(unsigned long).

I have a client iOS app that uses it, and everything works and runs as expected, except that I found I needed to include a minimal .cpp file in the client project to get the link to succeed. Otherwise I get C++-related unresolved symbols, e.g. operator new(unsigned long).

上述 hack 既简单又有效,所以我想我没有违反任何法律,但是有没有合适的方法来消除我的链接器错误?

The above hack is easy and effective, and so I guess I'm not breaking any laws, but is there a proper way to eliminate my linker errors?

推荐答案

应该只是将 -lc++ 添加到项目设置中的链接器标志的问题,我想.

Should be just a matter of adding -lc++ to the linker flags in the project settings, I'd have thought.

在项目设置的构建设置"选项卡的链接"部分下的其他链接器标志"下添加它.

Add it under "Other Linker Flags" under "Linking" section of the "Build Settings" tab on your project's settings.

这篇关于我应该如何让 Xcode 链接使用 C++ 静态库的 iOS 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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