Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gmp.h file not found error in Xcode, mac

Tags:

c++

c

xcode

macos

gmp

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???

like image 877
Q123 Avatar asked Apr 02 '14 00:04

Q123


2 Answers

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.

like image 155
Brett Hale Avatar answered Oct 18 '22 10:10

Brett Hale


First of all, you should not untar it in /usr/local. Just untar it somewhere in your home directory (it doesn't matter), then ./configure; make; make check; sudo make install.

Your problem may be caused by the compiler not searching /usr/local/include.

  1. Check that /usr/local/include/gmp.h exists. If it doesn't exist, GMP is installed incorrectly (or installed in a different location).

  2. Add -I/usr/local/include to your compiler flags. In Xcode, this is done by adding /usr/local/include to the "additional header search paths" in the project settings (or some setting like that).

like image 20
Dietrich Epp Avatar answered Oct 18 '22 11:10

Dietrich Epp