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.