xCode:与现有项目链接,从该项目导入文件
我在 xCode 4 中有一个 iOS 应用程序项目 ProjA,以及一个单独的 C++ 动态库项目 ProjB。我希望从 ProjB 导入特定文件以在 ProjA 中使用。
这是我所做的:
- 右键单击左侧项目导航器中的 ProjA.xcodeproj,选择“将文件添加到 ProjA..”,然后在文件浏览器中选择 ProjB.xcodeproj。
- 左键单击 ProjA.xcodeproj,然后在“构建阶段”下在“目标依赖项”和“链接二进制文件与库”中添加 ProjB.dylib。
我现在希望从 ProjA 中的 ProjB 导入 MyClass。因此,在 ProjA 类中,我尝试过:
#include "MyClass.h"
#import "MyClass.h"
..但是这些都没有在 ProjB 中找到 MyClass。
有人可以告诉我我做错了什么吗?真是令人沮丧!我用谷歌搜索了一下,似乎我正确地导入了项目,所以也许只是我的包含/导入需要调整。
非常感谢您抽出时间。
I have an iOS app project ProjA in xCode 4, and a separate C++ dynamic library project ProjB. I wish to import specific files from the ProjB for use within ProjA.
Here's what I've done:
- Right-click on ProjA.xcodeproj within project navigator on left, selected "Add files to ProjA..", then selected ProjB.xcodeproj in file browser.
- Left-click on ProjA.xcodeproj and under 'Build Phases' added ProjB.dylib in both Target Dependencies and Link Binary With Libraries.
I now wish to import MyClass from ProjB within ProjA. Thus in a ProjA class I have tried:
#include "MyClass.h"
#import "MyClass.h"
..but neither of these locates MyClass within ProjB.
Could someone please tell me what I'm doing wrong? It's very frustrating! I've googled around and it seems I'm importing the project correctly, so perhaps it's just my include/import which needs adjusting.
Many thanks for your time.
好吧,我还没有弄清楚如何进行整齐的导入..所以现在我只是做了一个回溯到其他项目位置的相对路径。
此后我遇到了编译问题,XCode 无法解析我其他项目中的 cpp。该问题是由于将 cpp 文件导入到 .m 文件中造成的。我将此 .m 文件重命名为 .mm,一切都编译正常!因此,请按照我所做的步骤操作,然后将要导入 .cpp/.mm 文件的 Obj-C 文件 MyFile.m 重命名为 MyFile.mm
Well I haven't figured out how to do a neat import.. so for now I've just done a relative path that backtracks to the other project location.
I had compilation troubles after this, XCode wouldn't parse the cpp in my other project. The problem was due to importing the cpp files into a .m file. I renamed this .m file to .mm and everything compiled fine! So follow the steps I did, then rename whichever Obj-C file MyFile.m you're importing .cpp/.mm files into to be MyFile.mm