Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GMP in Xcode 4 -- linking problems

Tags:

xcode4

gmp

I am trying to use the GMP 5.0.2 libraries in a demo C++ project in Xcode 4.0.2, but I'm having trouble getting the linking to work.

I looked at the comments in the StackOverflow post: Adding Linker Flags in Xcode, found the GMP library and header files in /usr/local/lib and /usr/local/include and dragged them to the project target. This allowed the project to compile, but apparently not to link. The error I'm getting is

    Undefined symbols for architecture x86_64:
  "operator>>(std::istream&, __mpz_struct*)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any suggestions for what I should try next? Thanks.

#include <iostream>
#include "gmp.h"
#include <stdio.h>

using namespace std;

int main (int argc, const char * argv[])
{

    mpz_t x;
    mpz_init(x);
    cin >> x;
    cout << "x = " << endl;

    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}
like image 543
user813869 Avatar asked Jul 09 '26 16:07

user813869


1 Answers

To run your program with GMP, remember to add the -lgmp flag to the linker, like so: (via Rob Keniger):

Right-click the target in the Xcode Groups and Files list and select Get Info from the contextual menu. In the Build tab, type linker into the search field and then locate the Other Linker Flags item.

Double-click the Other Linker Flags item and add -lgmp.

like image 65
nes1983 Avatar answered Jul 14 '26 00:07

nes1983



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!