1

I'm trying to use the Number Theory Library (NTL) to do some research. I was using the g++ compiler until I realized I need to use the C++ random library (which apparently isn't included in g++). So I then switched to compiling with clang++ with the following parameter (with output). It works with g++, if I don't include the random library (but obviously I need that for some functionality).

clang++ -Wall -O3 -std=c++11 -stdlib=libc++   -c -o Multimap.o Multimap.cpp
clang++ -Wall -O3 -std=c++11 -stdlib=libc++   -lgmpxx -lgmp -lntl -lm main.cpp Multimap.o -o ggh
Undefined symbols for architecture x86_64:
  "std::basic_ios<char, std::char_traits<char> >::operator!() const", referenced from:
      std::istream& NTL::operator>><NTL::ZZ_p>(std::istream&, NTL::Vec<NTL::ZZ_p>&) in libntl.a(ZZ_pX.o)
      NTL::operator>>(std::istream&, NTL::ZZ&) in libntl.a(ZZ.o)
      std::istream& NTL::operator>><NTL::ZZ>(std::istream&, NTL::Vec<NTL::ZZ>&) in libntl.a(ZZX.o)
      std::istream& NTL::operator>><NTL::zz_p>(std::istream&, NTL::Vec<NTL::zz_p>&) in libntl.a(lzz_pX.o)
  "std::istream::get()", referenced from:
      std::istream& NTL::operator>><NTL::ZZ_p>(std::istream&, NTL::Vec<NTL::ZZ_p>&) in libntl.a(ZZ_pX.o)
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
      NTL::operator>>(std::istream&, NTL::ZZ&) in libntl.a(ZZ.o)
      std::istream& NTL::operator>><NTL::ZZ>(std::istream&, NTL::Vec<NTL::ZZ>&) in libntl.a(ZZX.o)
      std::istream& NTL::operator>><NTL::zz_p>(std::istream&, NTL::Vec<NTL::zz_p>&) in libntl.a(lzz_pX.o)
  "std::istream::peek()", referenced from:
      std::istream& NTL::operator>><NTL::ZZ_p>(std::istream&, NTL::Vec<NTL::ZZ_p>&) in libntl.a(ZZ_pX.o)
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
      NTL::operator>>(std::istream&, NTL::ZZ&) in libntl.a(ZZ.o)
      std::istream& NTL::operator>><NTL::ZZ>(std::istream&, NTL::Vec<NTL::ZZ>&) in libntl.a(ZZX.o)
      std::istream& NTL::operator>><NTL::zz_p>(std::istream&, NTL::Vec<NTL::zz_p>&) in libntl.a(lzz_pX.o)
  "std::ostream::operator<<(long)", referenced from:
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__I__ZN3NTL14BlockConstructEPNS_4ZZ_pEl in libntl.a(vec_ZZ_p.o)
      __GLOBAL__I__ZN3NTL5ZZ_pX4zeroEv in libntl.a(ZZ_pX.o)
      __GLOBAL__I__ZN3NTL10ZZ_pEInfoTC2ERKNS_5ZZ_pXE in libntl.a(ZZ_pE.o)
      __GLOBAL__I__ZN3NTL9ZZ_pInfoTC2ERKNS_2ZZE in libntl.a(ZZ_p.o)
      __GLOBAL__I__ntl_abort_cxx_callback in libntl.a(tools.o)
      __GLOBAL__I__ZN3NTL2ZZ4zeroEv in libntl.a(ZZ.o)
      __GLOBAL__I__ZN3NTL9FFTTablesE in libntl.a(FFT.o)
      ...
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_4 in libntl.a(vec_ZZ_p.o)
      ___tcf_16 in libntl.a(ZZ_pX.o)
      ___tcf_1 in libntl.a(ZZ_pE.o)
      ___tcf_3 in libntl.a(ZZ_p.o)
      ___tcf_0 in libntl.a(tools.o)
      ___tcf_25 in libntl.a(ZZ.o)
      ___tcf_4 in libntl.a(FFT.o)
      ...
  "std::cerr", referenced from:
      NTL::Error(char const*) in libntl.a(tools.o)
      NTL::IntValToChar(long) in libntl.a(tools.o)
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
      std::ostream& NTL::operator<<<NTL::ZZ_p>(std::ostream&, NTL::Vec<NTL::ZZ_p> const&) in libntl.a(ZZ_pX.o)
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
      NTL::Error(char const*) in libntl.a(tools.o)
      NTL::IntValToChar(long) in libntl.a(tools.o)
      NTL::PrintDigits(std::ostream&, long, long) in libntl.a(ZZ.o)
      NTL::operator<<(std::ostream&, NTL::ZZ const&) in libntl.a(ZZ.o)
      std::ostream& NTL::operator<<<NTL::ZZ>(std::ostream&, NTL::Vec<NTL::ZZ> const&) in libntl.a(ZZX.o)
      ...
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)", referenced from:
      std::ostream& NTL::operator<<<NTL::ZZ_p>(std::ostream&, NTL::Vec<NTL::ZZ_p> const&) in libntl.a(ZZ_pX.o)
      NTL::PrintDigits(std::ostream&, long, long) in libntl.a(ZZ.o)
      std::ostream& NTL::operator<<<NTL::ZZ>(std::ostream&, NTL::Vec<NTL::ZZ> const&) in libntl.a(ZZX.o)
      std::ostream& NTL::operator<<<NTL::zz_p>(std::ostream&, NTL::Vec<NTL::zz_p> const&) in libntl.a(lzz_pX.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • Possible duplicate: http://stackoverflow.com/questions/7533321/error-when-compiling-some-simple-c-code (Top answer mentions Clang) But I'm not sure enough to actually close this question. – Mysticial Jul 18 '14 at 18:46
  • @Mysticial He's using clang++, so the linker is linking in the c++ libraries. I think the error is probably that the library he wants to use links against libstdc++ instead of libc++. – bames53 Jul 18 '14 at 18:48
  • @bames53: that works, but now I'm getting: `fatal error: 'random' file not found #include ` – Andrew Russell Jul 18 '14 at 18:52
  • @AndrewRussell Well if you changed to linking against libstdc++ instead of libc++ then `` doesn't work because the version of libstdc++ you're using doesn't have ``. You need either a version of NTL that was compiled against libc++, or you need to link in both libstdc++ and libc++ (which is possible because libc++ uses inline namespaces and maintains some ABI compatibility with libstdc++). Another option would be to use an updated version of libstdc++ that has C++11 support. – bames53 Jul 18 '14 at 18:56
  • Would you know how to updated libstdc++ on OS X? Anything that I find essentially says: use libc++ because it's standard for OS X. – Andrew Russell Jul 18 '14 at 19:12

0 Answers0