0

I was able to setup BlockSci on macOS v10.13 (High Sierra) 10.13.6. The setup installed header files in /usr/local/include and a libblocksci.dylib in /usr/local/lib. The C++ code I am trying to compile is:

#include "blocksci.hpp"
#include <iostream>
#include <string>

int main(int argc, const char * argv[]) {
    blocksci::Blockchain chain{"path/config.json"};
    return 0;
};

The compile command I am using for hello.cpp is:

g++ -std=c++17 -L/usr/local/lib -I/usr/local/include/blocksci -I/usr/local/include/blocksci/external -o hello hello.cpp

However, the symbols for the BlockSci library are not found:

Undefined symbols for architecture x86_64:
  "blocksci::Blockchain::Blockchain(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in hello-942a60.o
  "blocksci::Blockchain::~Blockchain()", referenced from:
      _main in hello-942a60.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What am I doing wrong when I try to compile this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hahnemann
  • 4,378
  • 6
  • 40
  • 64
  • 1
    You told g++ *where* to find libraries, but you didn't tell it *which* libraries. – n. m. could be an AI May 03 '22 at 21:37
  • 2
    Does this answer your question? [How to include needed C library using gcc?](https://stackoverflow.com/questions/6016815/how-to-include-needed-c-library-using-gcc) – Siguza May 03 '22 at 22:27
  • I tried `g++ -std=c++17 -L/usr/local/lib -llibblocksci.dylib -I/usr/local/include/blocksci -I/usr/local/include/blocksci/external -o hello hello.cpp` but it still does not work, with an error `ld: library not found for -llibblocksci.dylib clang: error: linker command failed with exit code 1 (use -v to see invocation)`. – Hahnemann May 04 '22 at 16:26
  • 1
    `-l` option is what you need but it doesn't work the way you think. Please read the manual (perhaps `man gcc`, not sure how to do this on your system but you can find it online). Yes it's long, but it's searchable. I could quote the relevant section but where's the fun in that? – n. m. could be an AI May 04 '22 at 20:24

1 Answers1

0

I found this and this that were helpful. It finally compiled with:

g++ hello.cpp -std=c++17 -I/usr/local/include/blocksci/external -o hello -L/usr/local/lib -lblocksci -Wl,-rpath,/usr/local/lib

However, now I get a runtime error:

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error
Abort trap: 6

Back to the drawing board, but it compiled for now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hahnemann
  • 4,378
  • 6
  • 40
  • 64