How do I link libraries in Xcode 4?
I’m a complete beginner to Apple’s Xcode, but I have followed the Xcode documentation and the advice of a few related questions without success.
I installed GMP to /usr/local/bin, wrote a short program using the library, and compiled with
gcc main.c -lgmp. It compiled with no warnings or errors, and the executable worked flawlessly.
I started a new Xcode project (Command Line Tool; Type: C), copied the code to the newly created main.c, and opened the project build settings. From there I set Linking > Other Linker Flags to
-lgmp and Search Paths > Library Search Paths to
/usr/local/bin. However, the build fails with the preprocessor error “Gmp.h: No such file or directory”.
I have tried almost every header imaginable:
#include "libgmp.a" . . .
This has been my main obstacle over the last three months which has prevented me from learning C. Any help leading me to an eventual solution would be greatly appreciated.
- How to use c++ and objective-c together in XCode 4.2
- Using C++0x in Xcode 4.2 project via CMake
- SDL Error Undefined symbols for architecture x86_64 “_SDL_main”
- Compile C code and expose it to Swift under Linux
- How to use SCNetworkReachability in Swift
- Memory goes on Increasing each time the interstitial ad is display in unity 5
2 Solutions Collect From Internet About “How do I link libraries in Xcode 4?”
There’s a few things you have to set up in your Xcode project. For example, I have gmp installed in
/opt/gmp/5.0.2 and I will use that as an example. The actual library is installed into
/opt/gmp/5.0.2/lib and the header files into
/opt/gmp/5.0.2/include. When installing the library setting the –PREFIX flag to
/opt/gmp/5.0.2 would handle this automatically. If you don’t set this flag the prefix is usually set to
/usr/local by default.
- The Other Linker Flags looks right, it should be the name of the library.
- Set the Header Search Path to the include directory, in my case
- Set the Library Search Path to the lib directory, in my case
Since the header search path has been set, you should now be able to include the header file like this:
Of course, replace
/opt/gmp/5.0.2 with the PREFIX path you used when you installed gmp.
Lastly, you typically don’t install libraries to
/usr/local/bin, you would install to
/usr/localand let any binaries be installed into bin while libraries like these would be installed into lib. Of course any path scheme would work, I usually recommend
/opt/<project-name>/<version-number> since it allows me to keep better track of what I have installed and have multiple versions of the same libraries and tools without having to deal with collisions.
I have updated my system from snow leopard to mountain lion and had to install
First of all I have installed Xcode CommandLineTools set.
Secondly, installed Homebrew. Then with it I have done steps in this topic: https://apple.stackexchange.com/questions/38222/how-do-i-install-gcc-via-homebrew
In my last step, made changes to an xcode project as colleague Marcus Karlsson told.
It’s finally working! Very big Thank You 🙂
- how to throw errors in a closure in swift?
- maintaining selection in UISegmentedControl
- Stop Background audio while starting
- SWIFT: google maps draw waypoint polyline
- Using XCode Instruments on hackintosh
- iOS custom shape navigation bar
- how to read firebase database
- Dismiss pushed view from within Navigation Controller
- How to share NSData or phasset video using Facebook iOS SDK 4.0 FBSDKShareDialog
- Parse iOS – How to query PFUser details from another class
- How to stop/cancel playSoundFileNamed in Swift?
- How to clear preference iOS push notifications for my application?
- Where to add topLayoutGuide constraint code
- Why isn't is possible to append a String! via += operator?
- Making phone calls on the iPhone