简体   繁体   English

Xcode:C++:在项目中包含库

[英]Xcode: C++: including library in project

How do I create a new project in Xcode and use this library libStanfordCPPlib.a As you see in the img, I have the library file in my project folder.我如何在 Xcode 中创建一个新项目并使用这个库libStanfordCPPlib.a正如你在 img 中看到的,我的项目文件夹中有库文件。 Yet I can not include any of its classes / functions.但是我不能包含它的任何类/函数。

代码

您需要链接 lib 文件,找到 libStanfordCPPLib.a 的路径名,然后单击左侧面板上的“Assignment2”项,然后找到 build-phase 选项卡,然后搜索 Use Lib Path 然后将库文件夹路径粘贴到那里.

have you #included the header?你有#include 标题吗? have you selected the library in link binary with libraries?您是否选择了链接二进制库中的库? is the header search path valid?标题搜索路径有效吗? if the error is that the compiler cant include the header, it will be a header path problem.如果错误是编译器不能包含头文件,那将是头文件路径问题。 if the error is at linking, you havent added the library correctly.如果错误发生在链接时,则说明您没有正确添加库。

I had a similar problem.我有一个类似的问题。

Right click on the .a file (libStanfordCPPLib.a) and select "Show File Inspector"右键单击 .a 文件 (libStanfordCPPLib.a) 并选择“显示文件检查器”

In the "Inspector" window, press the "Localize" button.在“检查器”窗口中,按下“本地化”按钮。

I'm not sure, honestly, what this did different, so if anyone can explain that, go for it.老实说,我不确定这有什么不同,所以如果有人能解释一下,那就去做吧。

I'll say that in my case, the .a file seemed to be localized already, and all references seemed to be set right.我会说,就我而言,.a 文件似乎已经本地化,并且所有引用似乎都设置正确。

How did I get to the state that I was in just before the Localize button worked?我是如何进入 Localize 按钮工作之前的状态的? Right click on the Project ("Projectx").右键单击项目(“Projectx”)。
In the menu, click on "Add files to 'Projectx')..." I selected Destination check box (checked) to copy files into destination folder if needed.在菜单中,单击“将文件添加到 'Projectx')...” 如果需要,我选择了目标复选框(选中)以将文件复制到目标文件夹中。 I chose "Create folder references for any added folders" I chose "add to targets: Projectx"我选择了“为任何添加的文件夹创建文件夹引用”我选择了“添加到目标:Projectx”

That's about it.就是这样。 my header file referenced in the .a kept failing.我在 .a 中引用的头文件一直失败。 Then I clicked the "Localize" button mentioned above and it all worked.然后我点击了上面提到的“本地化”按钮,一切都奏效了。

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

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