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
Related
After upgrading my MacBook Pro to OS X 11.1 Big Sur, I am unable to get compilation of c++ programs using gcc to work.
I am using CLion with CMake, and I get the following error when reloading the CMake configuration
ld: library not found for -lgcc_s.10.4
The things that I have tried are installing Xcode, it installed without error.
I have tried to create a symlink as suggested here https://github.com/Paxa/fast_excel/issues/33
$ cd /usr/local/lib
$ sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.4.dylib
It appears that the library libSystem.B.dylib is not present. Some sites mention that the libraries starting with Big Sur reside in some "shared cache", which I have no idea of what it is and how to access it, let alone make ld access it on its own.
Any suggestions on how to solve this are very welcome. Thank you!
According to this answer you should use: g++-10 -o main main.cpp
The correct path of brew installed g++ in MacOS is:
$ which g++-10
> /usr/local/bin/g++-10
--
$ which g++
> /usr/bin/g++ //this is alias of clang (same for lyb)
If you use CMakeLists.txt file you will configure it like this:
set(CMAKE_CXX_COMPILER "/usr/local/bin/g++-10" CACHE STRING "C compiler" FORCE)
set(CMAKE_C_COMPILER "/usr/local/bin/gcc-10" CACHE STRING "C++ compiler" FORCE)
set(CMAKE_CXX_STANDARD 17)
In general, gcc tends not to work on more recent versions of Mac OS. The solution is to use the build in C/C++ compilers. To automatically use these, instead of GCC, set these environment variables:
CC="clang"
CXX="clang++"
This will use the built in Mac compilers. Once doing this, I have yet to run into an issue with compiling that wasn't due to the actual code being compiled.
Thank you for all the answers highlighting different things that could solve the issue. What ended up working was to run brew reinstall gcc, and pointing CLion (or plainly CMake as Mike mentioned) to use the correct compiler (something that I had already done, but I want to mention it here if anyone else finds this question and has the same problem), the paths that I use are
/usr/local/Cellar/gcc/10.2.0/bin/gcc-10
/usr/local/Cellar/gcc/10.2.0/bin/g++-10
These paths are actually just the explicit locations that are linked from
/usr/local/bin/g++-10
/usr/local/bin/gcc-10
Also, as Matt Braunstein mentioned, it is possible to use clang that is supplied with Mac OS X, something I did while figuring out how to solve my issues with gcc.
My thoughts on the problem is that somehow, installing gcc with homebrew didnt install everything needed as it appeared to already be installed from a previous version, the reinstall command seemed to rectify this.
Again, thank you for the answers that helped me find this solution, and possible workarounds.
I spent hours trying to solve this compilation problem with cmake, the original statement in CMakeLists.txt for library linkage is!
link_directories(/usr/local/lib)
target_link_libraries(Program libsndfile.dylib)
With error message after make:
ld: library not found for -lsndfile
The solution that works is to add the entire path like this:
target_link_libraries(Program /usr/local/lib/libsndfile.dylib)
There is no need to have this in Ubuntu, but somehow the new MacOS requires it.
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
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.
I am taking over a project and am pretty new with this entire setup (linux/gdb/c++). This project did work at 1 point, on RaPi 1.
Using VisualGdb to compile a c++ program to run on a RaspberryPi 2. I've seen similar questions, but either the answers didn't work or I don't fully understand how to implement.
When I try to compile, I get a fatal error: library name: No such file or directory.
2 that I know of so far are:
include "Poco/Data/Common.h"
include "Poco/Data/SQLite/Connector.h"
I have a similar program that uses different poco libraries and it compiles fine. If I look in the External Dependencies of the project, I see Common.h and Connector.h. The GDB Makefile settings have pthread PocoFoundation PocoData PocoDatad PocoDataSQLite PocoDataSQLited libraries listed.
Tried a few things, but not really sure how to debug this. I don't seem to be able to find the files on the RaPi using find -iname "Common.h", but I can't find the ones that are working in the other project either using that method.
I've done the Complete Edition install of poco and run sudo apt-get update; sudo apt-get upgrade; sudo rpi-update.
Tried to give as much info as I understand of this, but sure I missed something. Any help/suggestions would be great. Let me know if you need more info on something I didn't include.
Thanx ahead of time.
In case anyone else has this issue.
libmysqlclient-dev needs to be installed first for these libraries to get installed with the poco install.
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