1

i'm trying to get GMP working with Xcode. So far I have untared the file in the home directory, ran all the necessary commands to have it configure, make, and install

./configure --prefix=/usr/local --enable-cxx
make
make check
sudo make install

Both the gmp.h and gmpxx.h are in the usr/local/include, however I still am getting an error when trying to include the files. I believe I need to add a complier flag but for this version of Xcode I do not know how to do that. If that is not the case and I need to do something else please advise and I would very much appreciate it.

My code looks like the following:

#include <iostream>
#include <gmp.h>
int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

Can I code with GMP in c++ ? Or do I need code in c? Any help getting this to work would be very much appreciated, thanks a ton in advance!

Sorry if this seems like a DUPLICATE question, i did look at the other questions and I was not able to get it to work following answers from previous questions.

UPDATE

Added the libgmp.la and libgmpxx.la to Xcode, also added /usr/local/include to header file search and it is still not working! I see the library files in my project and if I put "gmp.h" instead of it works but when I go to use GMP it fails telling me to chnange the in other GMP files to "gmp.h" which doesn't seem right.

ANY IDEAS?

Jared Smith
  • 421
  • 3
  • 6
  • 18
  • You may need to add somehow `-I/usr/local/include` switch in order to specify custom include path. I am not familiar with Xcode, but there should some thing like "Additional header path". – Grzegorz Szpetkowski Nov 02 '14 at 21:23
  • I thought that may be the case, and I very much think you are correct. I been trying to find where to add this for sometime now, I can't seem to find it – Jared Smith Nov 02 '14 at 21:33
  • See http://stackoverflow.com/a/14153027/586873 for setting include path. You might also need to specify custom library path as `-L/usr/local/lib` and tell to use it by `-lgmp`. See also http://stackoverflow.com/questions/13955996/linking-gmp-to-xcode-4-5 for whole procedure (in fact I think it's just duplicate of your question). – Grzegorz Szpetkowski Nov 02 '14 at 21:34
  • Would you know if the lib files in GMP are called libgmp.la and libgmpxx.la and if those are the only ones I need to include – Jared Smith Nov 02 '14 at 21:51
  • In your case you just neeed `libgmp.la`. The latter serves for additional [C++ Class Interface](https://gmplib.org/manual/C_002b_002b-Class-Interface.html#C_002b_002b-Class-Interface) (that one you enabled by `--enable-cxx` switch in `./configure` script). – Grzegorz Szpetkowski Nov 02 '14 at 21:58
  • Awesome, It seemed to find the header file now, but it made me use "gmp.h" instead of is that going to be a problem? Also If you are familiar with gmp can you provide a simple example using a gmp variable to hold a huge number, so i can mark it correct for your help! Thanks a ton – Jared Smith Nov 02 '14 at 22:04
  • `libgmp.la` is for libtool, not directly for linking. – Marc Glisse Nov 02 '14 at 22:05
  • If `"gmp.h"` works, `` should work just as well for you. – Marc Glisse Nov 02 '14 at 22:06
  • Ya its going to be a problem to have it as "gmp.h" i don't know why its not finding it with the – Jared Smith Nov 02 '14 at 22:09
  • I doesn't work because when I go to compile it fails telling me to change the to "gmp.h" in other files. I don't think changing this in every file is ok? Right> – Jared Smith Nov 02 '14 at 22:10
  • This is depressing, I have added the libraries, added my search headers to find the /usr/local/include and it still don't work... Any ideas? – Jared Smith Nov 02 '14 at 22:28

1 Answers1

-1
this is the fix according to another SO question:

1) Open the left panel, 
   goto "ProjectName", Targets, Build phases, Link binary with libraries 
   and select your library.

2) Open the left panel,
   goto "ProjectName", Project, Header Search Paths, 
   write the path where the headers of your library are 
   (the .h files, usually in /usr/local/include).

3) Open the left panel, 
   goto "ProjectName", Project, Library Search Paths, 
   write the path where your libraries are 
   (the .a or .dylib files, usually in /usr/local/lib)
user3629249
  • 16,402
  • 1
  • 16
  • 17
  • One of the nice people who cemmented showed me this link, I tried it but it didn't seem to work. Whats hard is that Xcode has changed since then, but no dice for me sadly. I really appreciate you taking the time to post this. I shall keep trying... – Jared Smith Nov 03 '14 at 04:11
  • 3
    Why would you put your whole answer in a code block? When citing something, it is nice to give a link. – Marc Glisse Nov 03 '14 at 06:19