Installing & Finding GMP under OSX - c++

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.

Related

Linking problem to libraries installed with Homebrew since Mojave update

I have recently updated to Mojave and since then am experiencing linking problems to libraries (gsl, Cuba etc.) that I had installed with Homebrew.
When compiling my code, gcc (tried g++-6 and g++-8, also installed with brew) does not seem to search the directories where brew stores the header files for those libraries. The code compiled when I manually set the paths to
GSL_INCLUDE_PATH=/usr/local/include/gsl/
GSL_LIB_PATH=/usr/local/lib/
CUBA_PATH=/usr/local/include/
But since I am using this in all my make-files I do not want to do this every time...
Before I was using Sierra and I have included in my .bash_profile the following:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
This seemed to do the trick before. But now /usr/local/sbin did not exist anymore. I ran brew doctor which suggested:
You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/Frameworks /usr/local/sbin
sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/sbin
I did just that and reinstalled the libraries but it did not sort out the issue.
I have tried to include
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/include:/usr/local/lib:$PATH
in the bash-profile, but that did not help either. (Maybe I did it wrong, I am not familiar with setting paths) At this point I am not sure whether brew installs the libraries in a weird place or if gcc just does not look in the correct location.
I have installed Xcode and the command tools. I have tried everything I found (and could understand) that I found as solutions for related problems.
I would like for gcc to look in the directories that brew installs the libraries to by default.
I would be really grateful for a suggestion of a clean fix for this issue.
Please excuse the long essay; if you need additional information please do tell, this ist my first time asking for help here.

How to compile Quantlib via Xcode?

I am trying to install QuantLib on my Mac running OSX 10.11.6. Installed Boost 1.59 via MacPorts and then followed these instructions.
I used these additional environment variables
./configure --with-boost-include=/opt/local/include/ \
--with-boost-lib=/opt/local/lib/ --prefix=/opt/local/ \
CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6' \
LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
and then make && sudo make install.
However when I run the Bermuda Swaption test it gave me the same error described here.
Little premise: I don't know anything about C++. I need QuantLib to work on Python. So I read carefully the answer by SmallChess and tried to solve it by myself. As I read in his answer
You can't just compile BermudanSwaption.cpp and hope everything would be fine. You have to compile the entire QuantLib library and link with the generated library files. Please google "compiling and linking C++" for more information.
By far, the easiest way to make it happen on Mac is to do it with Xcode. You will need to create a new Xcode project, and import the entire Quantlib project files into it. Next, you will need to create a main() function. Xcode does the compiling and linking for your automatically.
This is what I exactly did:
created a new project in Xcode (version 8.2.1)(file/new project/Command Line Tool/"HelloWorld"/Documents/create)
selected Targets, Build Phases and Link Binary With Library. Added libQuantLib.0.dylib
set libstdc++(GNUC++ standard library) as C++ Standard Library in Build Settings
Modified Header Search Paths to include: /opt/local/include/, and Library Search Paths to include: /opt/local/lib
C++ Language Dialect is set on Compiler Default.
Dragged the ql folder onto the left window of the Xcode
Now, I managed to copy a simple code which includes the library and even if there are many warnings, it runs. Still when I run on the Terminal the command for the Bermuda Swaption test I get the same error. What am I doing wrong?
Additional info (may or may not be useful): if I change the C++ Standard Library setting on Xcode to libc++, I get on Xcode the same error I get when i try the Bermuda Swaption test (ld: symbol(s) not found for architecture x86_64).
Any help would be very much appreciated
Regards
EDIT: you can find a picture of the code at https://i.stack.imgur.com/1zhjO.png

Link the gmp library with Xcode 7.2

I try to link the gmp library with Xcode. This is what I (with the help of multiple stackoverflow articles) did:
I downloaded the gmp file and installed it (in the default location: /usr/local ) using "sudo make install" and I checked it with "make check".
In Xcode I added under "Other Linker Flags" (as described in multiple articles) -lgmp. I also tried -lgmpxx.
In main I included <stdio.h> and <gmp.h>.
After all I still got the error: " 'gmp.h' file not found ", which indicates that the library is not properly linked. I don't see what I am doing wrong. Suggestions would be appreciated. Thanks in advance!
To get C++ support, you need to run
./configure --enable-cxx
plus any other desired/required options, see https://gmplib.org/manual/Build-Options.html, before running
make install

Install GMP library on Mac OS X 10.9 and Xcode

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.

SDL.h not found on g++ compile

Using OSX and vim...
Downloaded SDL2 from the website, then moved the SDL2.framework into /Library/Frameworks/
Using tutorial code, and Makefile... SDL.h is not found.
Makefile: g++sdl-config --cflags --libssdltest.cpp -o sdltest
I've read numerous things about pointing the compiler to the framework, but everything I've tried doesn't seem to work, and I thought /Library/Frameworks/ was the default area for the compiler to look
Got it to work.
Getting this to work took multiple tries, but the root of the issue for each try was that most of the Tutorials I was looking at were for SDL1.2 when I was using SDL2.
This changed flags in the make file, directories to search in and other things. Interestingly, I could never get the compiler to see SDL.h when it was in the /Library/Frameworks/ directory. However using Macports to install SDL2 allowed me to point the compiler to where Macports installed SDL2 header files - /opt/local/include/SDL2
That seems to have done it for me
Thank you for your question, because I was having similar difficulties! There seems to be a dearth of detailed and helpful tutorials on how to install SDL2 using Macports.
I got it working! Here are the steps:
Visit this link to find the Macports package appropriate for your version of Mac OS X. Install the version you need, and once that is done, proceed to step 2.
https://www.macports.org/install.php
After installation is done, visit this link to find the SDL2 port.
https://www.macports.org/ports.php?by=name&substr=libsdl
The one I needed was the third from the top, called libsdl2. I will be providing the name for you so feel free to visit the link simply for your own edification.
Open the Terminal, and type sudo port install libsdl2. If all goes to plan, you should see it installing and updating. Once it is complete, you should have a functional installation of the SDL2 Header files, (ending in .h), Static Library files (ending in .a) and Dynamic Library files (which contain dylib). You may have to do some poking around in Finder to locate where it installed.
The advantage of this workaround is the ability to use SDL with other IDE's besides Xcode, Eclipse for instance. Whereas Xcode requires you to assign a path of /Library/Frameworks, this technique should allow you to use the IDE of your choosing.
The final step is going into your IDE and assigning the build paths to these newly installed and compiled SDL files. For instance, the paths for mine are /opt/local/include and /opt/local/lib. Be mindful of the fact that your path may differ from these, but these examples should give you an idea of where to look.
Hopefully this is helpful for somebody!