简体   繁体   中英

GMP library 6.0.0 doesn't compile on Mac OS Mavericks

I am trying to compile this example program

#include <iostream>
#include <gmpxx.h>


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

    mpz_class rho = 3;
    std:cout << rho;

    return 0;
}

and I get this error:

Undefined symbols for architecture x86_64:
  "___gmpz_clear", referenced from:
      __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() in main-5858d5.o
  "___gmpz_init_set_si", referenced from:
      __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long) in main-5858d5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I compile my main manually with this command:

clang++ -L /opt/local/lib -I /opt/local/include -lgmpxx main.cpp

GMP has been installed through MacPorts:

$port list gmp
gmp                            @6.0.0          devel/gmp

Compiler's info:

$clang++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix

some more info:

ll /opt/local/lib/libgmp*
/opt/local/lib/libgmp.10.dylib
/opt/local/lib/libgmp.a
/opt/local/lib/libgmp.dylib -> libgmp.10.dylib
/opt/local/lib/libgmpxx.4.dylib
/opt/local/lib/libgmpxx.a
/opt/local/lib/libgmpxx.dylib -> libgmpxx.4.dylib

and:

ll /opt/local/include/gmp*
/opt/local/include/gmp.h
/opt/local/include/gmpxx.h

运行clang++ -L /opt/local/lib -I /opt/local/include -lgmpxx -lgmp main.cpp用@nm来解决问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM