Link External Library in Xcode C++ Project - c++

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. 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. When I try to add a library, a list box pops up showing two folders: "OS X 10.11" and "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.
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. 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?

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. 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!

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:

According to this, you can try:
1) Open the left panel, goto "ProjectName", Targets, Build phases,
Link binary with libraries and select your library.
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).
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)
I hope you can confirm that this work for Xcode7.
On Step 1) You can also:
Under "Link Binary With Libraries", click on the plus button.
Click "Add Other..." (this is a 3rd party library).
Choose the filename (/usr/local/lib/libavutil.a).
P.S., I can't flag as a Dup, because that was not an acepted answer

Related

Is it possible to link dylib without header file?

I'm working on Mac OS and using CLion/Xcode IDEs. I've already read a lot of information about dynamic libraries. Is it possible to link my dylib to the project without writing "include "name_file.h"" on my Macbook? I know if it is possible in Visual Studio on Windows. VS on Mac OS doesn't support C++.
To link a library in XCode, left click the project name in the source panel to the left. At the top click the "Build Phase" tab. You will see a drop down "Link Binary with Library" click the drop down then hit the "+" symbol and locate the dylib. Then compile your code.

How can I link winpcap in Code Blocks?

Id like to know the process to link the Wincap library and use it in my c++ project im developing in Code Blocks.
After struggling to do this myself I figured that I should post my solution here.
You will need to download the developer version of WinPCap and unzip it somewhere, lets say "C:\WpdPack_4_1_2".
In Code::Blocks, you need to add the "Include" sub directory to the search directories. To do this, go to settings->compiler and click on the "Search directories" tab. For the "Compiler" "Linker" and "Resource compiler" tabs you need to add the search path. Using the location above as an example, it would be C:\WpdPack_4_1_2\WpdPack\Include.
Once these have been added, click "OK" to return to the main screen.
Then, you need to add the library file to your project build settings. To do this, right click on your bolded project name on the left side and choose "Build options". Under the "Linker settings" tab add the path to the "libwpcap.a" file.
For example, it would be C:\WpdPack_4_1_2\WpdPack\Lib\libwpcap.a.
After I did this, the example programs compiled fine. Make sure to add the #include "pcap.h" in your program to use the library.

xcode: difference between adding a linker flag and "link binary with libraries"

I switched a few days ago from windows and I find a bit confusing the linking process in xcode.
I have a static library I want to use called nag C library whose file is "libnagc_nag.a".
If I add "/opt/NAG/clmi623dgl/lib/libnagc_nag.a" to "other linker flags", the program runs perfectly.
On the other hand, If i go to "Build Phases -> link binary with libraries -> + -> add other" and add "libnagc_nag.a", the library file now appears in the project navigator but I get the following error after the build succeeds and it tries to run it.
dyld: Library not loaded:
/fserver/mo/cl23/CL23.3/CLMI623DG_build/BUILD_mac_64/climp/LIBS/nag_lm/libnagc_nag.dylib
Referenced from: /Users/german/Library/Developer/Xcode/DerivedData/myproj-bjepqyzlzkayspddtaspmmzxgaid/Build/Products/Debug/myproj
Reason: image not found
my questions are:
Why is it any different?
does it think it's a dynamic library?
How can I solve this problem in the second case?
Edit: I removed a link to the article where I found the answer since it was outdated.
The problem is that the linker flag is the same for both, dynamic and static libraries, and the file extension is removed from it. So, if you have a static and a dynamic library with the same name and only different extensions, the linker will chose by default the dynamic version of the library. This happens even if you chose the the static version in the "link binary with libraries" menu. Then, if the app can't find the dynamic library there will be an error. So, the answers to the question are:
1) it wouldn't make any difference if there wasn't a dynamic library with the same name. 2) The linker only know the name of the library, so by default it choses the dynamic version. 3) The solution can be renaming the library or using the first method.
Does your project have multiple build targets? If so, did you add the library to the appropriate target? Check this by looking at "link binary with libraries" again or by selected the framework in the Project Navigator and looking at "Target Membership" in the File Inspector pane.
Also, is your framework search path set correctly? Click on your project at the top of your project navigator, then click on "Build Settings" in the top center of the screen, then go down to "Search Paths" and make sure an appropriate path is included.

how to link the fmod library in visual studio

I am just a beginner at windows programming and was reading a tutorial about it.
It said something about resources for menu creation.
I am working in visual studio 2010 and would like to know how to create these resources (the turorial said something about adding them to the compiler which i could not understand) for simple things like menu bar creation.
Please help me.(Please keep in mind that I am a beginner therfore explain in detail if possible.)
To actually use the additional functionality you have to include the header and specify the directory where it is contained so the project can find the file
right click on project->properties
C\C++->general tab
the top element is Additional Include Directories - click the down arrow and specify the path to the header file
For your application to use the functionality you have to link with the lib
right click on project->properties
Linker->general tab
The 9th element from the top is Additional Lib Directories
& specify the path to the accompanying lib file
NOTE that the dll that corresponds (if dynamically linked) must be either in the system path or in the working directory of your application
under the linker -> input tab
you'll want to specify the name of the .lib file to load (the same as the file contained within the path you specify to link with with)
Alternatively - if the you'd like to make a project depend on another project within the same solution
right click the project->properties
the top tab is Common Properties
within that tab click the button "Add New Reference" and select the project

Importing third-party library source files into Eclipse CDT

I've got a project set up very nicely with eclipse-cdt. I'm not building from eclipse, but the indexer works and all my makefile settings were picked up, including third party libraries headers.
What I would like, however, is to be able to view the actual source of those libraries - say, if I want to see some code in Qt or libc I'd like to be able to CTRL+click into the method from the relevant header file. You can do this in the java version of eclipse, whenever you are missing a source file, you have an option of "attaching source". I've looked everywhere with CDT and can't find a solution. I don't want to build these third party libs, I just want to be able to click-through to their source code, not only to their headers.
Does anyone know how to do this (am I missing something obvious)?
Ok, found the answer.
In the Project's Properties window, under "C/C++ General" there is a tab called "Source Location", your project's folder should be listed there. Click on "Link Folder", mark the "Link to Folder in the file system" and use "Browse" to find the folder where all he library's source code is.