Install GMP library on Mac OS X 10.9 and Xcode - c++

My question is as simple as the title. I have a Macbook Pro with OS X Mavericks (10.9.4) and Xcode (5.1.1). I need to install the GMP arbitrary precision libraries so that I can just get to write GMP-enabled programs from within Xcode.
I downloaded the package from the official website
I extracted it to my desktop
./configure --prefix=/usr/local --enable-cxx
make
make check
sudo make install
But when I go to Xcode and just #include <gmpxx.h> it doesn't find it. Also adding -lgmp to my linker flags causes an error.
I also tried using homebrew with brew install gmp but that didn't work either (same symptohms)
What is the correct way to solve this problem?

You need to ensure that you have an include path -I/usr/local/include, before you can include <gmpxx.h> (or <gmp.h> for that matter).
Also, adding -lgmp is insufficient, since that's only the C interface. You want to link with -lgmpxx (the C++ library), and possible specify the path to that library with -L/usr/local/lib.
You can run otool -L /usr/local/lib/libgmpxx.dylib, to ensure that libgmp.dylib is already linked to it. Which it should be.

Set the Header Search Path and Library Search Path in the Xcode Project Settings to /usr/local/include and /usr/local/lib respectively as, by default, these paths are not searched by Xcode.

Related

How to force CMake to ignore sytem db.h header file in favour of installed version on Mac?

I'm trying to port my CMake library to mac. I'm linking berkerly DB so I've installed it using brew and I'm able to find the appropriate paths (library, include etc) in cmake. They are
Berkerly
BERKELY_STATIC_LIBRARY /usr/local/lib/libdb.a
BERKELY_lIBRARY /usr/local/lib/libdb.dylib
BERKELY_INCLUDE_DIR /usr/local/include
However, my library doesn't compile because the dependency I am compiling includes db.h
#include <db.h>
which also exists at
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/db.h
and is being used in preference to the one at /usr/local/include. Is it be possible to force CMake to use the db.h from /usr/local/include instead of the other one?

Installing & Finding GMP under OSX

around a few days I am troubling an issue when installing the SCIP suite. SCIP requests the GMP Library:
src/rational.h:32:10: fatal error: 'gmp.h' file not found
#include "gmp.h"
To this end, I tried to install gmp according to the following two ressources:
Installing GMP on MacOS X with Xcode I tried gmp-6.1.0 aswell as gmp-6.0.0a
http://macappstore.org/gmp/ I checked the link via brew link gmp
I aswell checked and adjusted the shell paths, but it unfortunately does not work, the same errors occur as described above.
Could some of you recommend me another way to solve my problem?
Kind Regards
By the way, the easiest way to install gmp on a Mac is by using homebrew. You go to the homebrew website and copy the one-line installation script and paste it into Terminal. Then you can find any package you want like this:
brew search gmp
and install very simply with
brew install gmp
Anyway, back to your actual question... I suspect you have not set the Header search path correctly in Xcode.
First, you need to find where gmp.h is located, so do this in Terminal:
find /usr /opt -name "gmp.h"
I am guessing here that it is under /usr or /opt, but if you know you installed gmp elsewhere, replace /usr /opt with that place.
Sample Output
/usr/local/Cellar/gmp/include/gmp.h
That will tell you where it is located, then take the containing directory (i.e. the answer above MINUS the "gmp.h" bit at the end) and add it into Xcode Build Settings in the area marked in blue on the diagram. To get to the blue area, click first on the area marked in green, then yellow, then blue.
After following the answer from #Mark Setchell I hit lots of Undefined symbols for architecture x86_64: for every gmp API I had inside my C code.
To fix the error, I added a Linker flag inside my xCode project.

Importing Armadillo C++ library into Xcode

I'm a mac user and am trying to install and import C++ Armadillo library. Here are the steps I've had so far:
1) I downloaded the Armadillo library from its website.
2) I went over the Readme.txt file in the download file explaining how to install it.
3) I used CMake to make the armadillo download files into binary files.
4) Then by using terminal and the code sudo make install, I installed the binary codes and they generated some "library-like" files: libarmadillo.4.0.2.dylib, libarmadillo.4.dylib, lib armadillo.dylib
5) I then copied all these files into /url/lib directory.
6) Now I have my Xcode program running and I'm trying to include the armadillo library via the include command. The problem is Xcode highlights this line and it says "armadillo file not found". Could anyone please help me solve this issue?
Thanks very much,
You need to set the following things in your build settings:
Header Search Paths: /path/to/armadillo/include (e.g. something like /url/lib/armadillo/include)
This is all you need for your source to compile. However, in order to get your program to link, you will also need the following:
Library Search Paths: /path/to/armadillo/libraries (e.g. something like /url/lib/armadillo/lib)
Other Linker Flags: -larmadillo (or: add the armadillo library to your Link build phase using the GUI)
If you're not exactly sure how to properly build and install armadillo (e.g. which prefix to use when configuring), I highly recommend using a package manager such as MacPorts to do it for you,
Install port from here
run the following command:
sudo port install armadillo
Your header path and library path will be: /opt/local/include and /opt/local/lib respectively

ubuntu: including boost to eclipse CDT when installed from Aptitude

I am new to both C++ and eclipse and I am trying to use smart pointers.
I installed boost using aptitude:
sudo apt-get install libboost-all-dev
then in my eclipse project I added "boost" to
/ properties / c/c++build / settings / cross G++ linker / Libraries /
now in my C++ I try to include smart pointers:
#include <boost/smart_ptr.h>
but I am told : unresolved inclusion: boost/smart_ptr.h
I am really not sure why. From my (limited) understanding, I should not need to look for the path to to the libboost and to the include path of the compiler. I based this on the fact that I included other libraries installed by aptitude and I could include them in my code directly.
Sounds like a basic question, but all the threads I could find were either about windows, or about boost being downloaded and manually compiled (in which case I understand the path has to be given to the compiler).
Anything I am missing ?
Thx a lot

Installing multiple copies of library on Unix

So suppose I have installed the SFML 1.6 C++ library from the Ubuntu repositories. Then I have header files in /usr/include/SFML, library files in /usr/lib etc.
Now I have also downloaded a recent source tarball and built and installed SFML 2.0 into /usr/local.
So by default, if I #include , it gets the SFML 2.0 copy from /usr/local/include. Similarly, it links to libraries from /usr/local/lib.
My question is, how can I tell the compiler/linker to get the files from /usr/include and /usr/lib? I tried
g++ -I/usr/include
but it didn't work. Is this possible at all? Or should I just keep the 'home built' copy in a non system location?
Check the ldconfig command. I guess running it in the destination folder of the newer version of the library should do the trick.