gmp.h file not found error in Xcode, mac
c, c++, gmp, macos, xcode
Solution
C++ support is not enabled by default when configuring GMP. Untar the package, and configure with: `./configure --prefix=/usr/local --enable-cxx` - this will also install the `gmpxx.h` header, and the `libgmpxx.dylib` and / or `libgmpxx.a` libraries
Not sure if the latest GMP picks up clang for the C++ compiler. You can manually set the environment variables, e.g., `CC=clang` (C99 default), and: `CXX=clang++ -std=c++11 -stdlib=libc++` (C++11 dialect - also passes C++11 options to the linker). Again, this might be unnecessary.
Your test, since it includes C++, must be built as a C++ application. Also, `libgmpxx.dylib` is itself linked to `libgmp.dylib`, so for a simple C++ test program:
$CXX -I/usr/local/include gmptest.cc -o gmptest -L/usr/local/lib -lgmpxx
should be sufficient.
It may be necessary to prepend `/usr/local/lib` to the `DYLD_LIBRARY_PATH` variable, if other system GMP library installations are used first, unless you hardcode the library with the linker `-rpath` option. But that's something to worry about if and when the problem arises.
Problem
I downloaded `gmp-6.0.0a.tar.xz` file and unzip(tar) in `usr/local` directory. As people said , I typed `./configure`, `make`, `make check` and `sudo make install` in the `gmp-6.0.0` directory. Installing seemed fine. But when i tried to test like this ``` #include <stdio.h> #include <gmp.h> #include <gmpxx.h> int main(int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); return 0; } ``` it has error that `gmp.h` file not found. I added `-lgmp` to Other Linker Flags but not works. I do not know how to deal with this kind of problem. Could anyone help? Thank you Dietrich Epp. Now I do not have a error of not gmp.h file found but I do have gmpxx.h file not found. I don't know why.. Any suggestion???