简体   繁体   English

在Xcode C ++项目中链接外部库

[英]Link External Library in Xcode C++ Project

I've found answers to this question, but they don't work for me. 我已经找到了这个问题的答案,但是它们对我不起作用。 I'm trying to build a C++ project in Xcode that uses external libraries from ffmpeg and openCV, and I can't figure out how to link them. 我试图在Xcode中建立一个C ++项目,该项目使用ffmpeg和openCV的外部库,但我不知道如何链接它们。 As recommended, I go the "Build Phases" screen, and there's a place for "Link Binary with Libraries." 按照建议,我进入“构建阶段”屏幕,并且有一个“将二进制文件与库链接”的地方。 One of the libraries I need to link with is at /usr/local/lib/libavutil.a. 我需要链接的库之一位于/usr/local/lib/libavutil.a。 When I try to add a library, a list box pops up showing two folders: "OS X 10.11" and "Developer Frameworks". 当我尝试添加库时,将弹出一个列表框,其中显示两个文件夹:“ OS X 10.11”和“ Developer Frameworks”。 The library I need is not in either of these folders. 我需要的库不在这两个文件夹中。 I tried clicking on "Add Other" and a file chooser dialog comes up, but if I type "/usr/local/lib/libavutil.a" in the search box, the dialog doesn't accept it. 我尝试单击“添加其他”,然后出现一个文件选择器对话框,但是如果我在搜索框中键入“ /usr/local/lib/libavutil.a”,则该对话框不接受。

I've found that typing '-lswcale -lavcodec -lavdecice' etc. on the "Other linker flags" line in "Build Settings" works, but it's not what I hoped for. 我发现在“构建设置”的“其他链接器标志”行上键入“ -lswcale -lavcodec -lavdecice”等有效,但这不是我希望的。 I was hoping to get a file chooser dialog, where I could simply click on the libraries I want to use. 我希望获得一个文件选择器对话框,在这里可以简单地单击要使用的库。

Is there a way to accomplish what I want? 有没有办法实现我想要的?

Since nobody else has provided a working answer, I am documenting that the only only thing I have found that works it to set the search paths for the libraries under "Library Search Paths" and then to add a -l flag for each library in the "Other Linker Flags" section, just as you would on the command line command line: 由于没有其他人提供有效的答案,因此我在记录我发现的唯一东西,它可以在“库搜索路径”下设置库的搜索路径,然后为目录中的每个库添加-l标志。就像在命令行命令行中一样,“其他链接器标志”部分: 在此处输入图片说明

If I understand correctly what you are asking, you simply want to "set" the file chooser dialog at the right place, right? 如果我正确理解了您的要求,您只是想在正确的位置“设置”文件选择器对话框,对吗?

If so, you just have to press Cmd + Alt + G once you are in the file chooser dialog, after clicking on "Add Other..." in the "Link Binary with Libraries" menu. 如果是这样的话,在“文件链接二进制”菜单中单击“添加其他...”后,只需在文件选择器对话框中按Cmd + Alt +G A "Go to the folder:" dialog comes up, and there you can type the fullpath to the file or the folder you are looking for. 出现“转到文件夹:”对话框,您可以在其中键入要查找的文件或文件夹的完整路径。

Hope that helped! 希望能有所帮助!

According to this , you can try: 根据这个 ,你可以试试:

1) Open the left panel, goto "ProjectName", Targets, Build phases, Link binary with libraries and select your library. 1)打开左侧面板,转到“ ProjectName”,“目标”,“构建阶段”,“将二进制文件与库链接”并选择您的库。

2) Open the left panel, goto "ProjectName", Project, Header Search Paths, write the path where the headers of your library are (the .h files, usually in /usr/local/include). 2)打开左侧面板,转到“ ProjectName”,“项目”,“标题搜索路径”,输入库标题所在的路径(.h文件,通常在/ usr / local / include中)。

3) Open the left panel, goto "ProjectName", Project, Library Search Paths, write the path where your libraries are (the .a or .dylib files, usually in /usr/local/lib) 3)打开左侧面板,转到“ ProjectName”,“项目”,“库搜索路径”,写下您的库所在的路径(.a或.dylib文件,通常在/ usr / local / lib中)

I hope you can confirm that this work for Xcode7 . 我希望您可以确认这项工作适用于Xcode7

On Step 1) You can also: 在步骤1)中,您还可以:

  • Under "Link Binary With Libraries", click on the plus button. 在“将二进制文件与库链接”下,单击加号按钮。

  • Click "Add Other..." (this is a 3rd party library). 单击“添加其他...”(这是第3方库)。

  • Choose the filename (/usr/local/lib/libavutil.a). 选择文件名(/usr/local/lib/libavutil.a)。

PS, I can't flag as a Dup, because that was not an acepted answer PS,我不能将其标记为Dup,因为不是公认的答案

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

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