Monday, June 29, 2015

NTL library: symbol(s) not found for architecture x86_64


It took me a few days to resolve this problem with the NTL library on Mac OS X.
http://www.shoup.net/ntl/doc/tour-unix.html

So I am going to share the solution with anyone who might run into this problem.

The error:

ph$ clang++ -v -g -O2   -o bv_scheme NTL_examples.o  -lm -lgmp -lntl
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o bv_scheme NTL_examples.o -lm -lgmp -lntl -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "NTL::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, NTL::ZZ const&)", referenced from:
      _main in NTL_examples.o
  "std::istream::get()", referenced from:
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
  "std::istream::peek()", referenced from:
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
  "std::ostream& std::ostream::_M_insert<long>(long)", referenced from:
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__sub_I_lip.c in libntl.a(lip.o)
      __GLOBAL__sub_I_tools.c in libntl.a(tools.o)
  "std::ios_base::Init::~Init()", referenced from:
      __GLOBAL__sub_I_lip.c in libntl.a(lip.o)
      __GLOBAL__sub_I_tools.c in libntl.a(tools.o)
  "std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
  "std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::cerr", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Because Mac OS X now using libc++ rather than libstdc++, so you will need to compile the NTL library with libc++. You have to force it to use the libc++ option. The new compiling steps:

1. ./configure  NTL_GMP_LIP=on
2. open makefile under src/ and change to the following
CXX=clang++
# A C++ compiler, e.g., g++, CC, xlC 
LDLIBS=-lm -lc++
# libraries for linking C++ programs

3. make & sudo make install

Then you should be able to use the NTL library natively in Mac OS X.

No comments:

Post a Comment

RISC-v emulator

Changes are based on https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html For Ubuntu/Debian, in addition to sud...