2

Disclaimer: I'm aware of questions like this and this but nothing helped me to solve my problem.

I'm trying do compile a larger project dependent on ROOT package, and I was able to reproduce the error I'm facing in minimal example:

test.cpp:

#include "Math/GenVector/GenVector_exception.h"
int main()
{
  ROOT::Math::GenVector::Throw("foo");
}

compiled with: g++ -lGenVector test.cpp gives:

/tmp/ccq9A45m.o: In function `main':
test.cpp:(.text+0xc): undefined reference to `ROOT::Math::GenVector::Throw(char const*)'
collect2: error: ld returned 1 exit status

localizing libGenVector.so with ld --verbose -lGenVector | grep "lib GenVector.so succeeded" gives:

attempt to open //usr/local/lib/libGenVector.so succeeded

checking if symbol is defined in library with nm -DgC --defined-only /usr/local/lib/libGenVector.so| grep Throw gives:

000000000003f180 T ROOT::Math::Throw(ROOT::Math::GenVector_exception&)
000000000003f1e0 T ROOT::Math::GenVector::Throw(char const*)

Basing on answer to this question, I also tried to compile with -std=c++11 and -std=c++14 and -std=c++17 but everything gives the same error message.

pseyfert
  • 3,263
  • 3
  • 21
  • 47
  • 4
    Order matters! If source, object file or library `A` depends on library `B`, then `A` must come before `B` on the command line. – Some programmer dude Aug 01 '18 at 10:03
  • oh, great, and I see `g++ test.cpp -lGenVector` works! thanks, @Someprogrammerdude, if you write it as an answer, I'll accept it. – Przemysław Czechowski Aug 01 '18 at 10:18
  • In practice (not related to what was the problem), with root I found it more useful to check the rootmap files before checking the contents of .so files for a sort of human readable lookup "which so should I link against to use which class" (doesn't come with dependencies though). – pseyfert Aug 01 '18 at 13:15
  • And, for the c++ standards, I would use `root-config --cflags` rather than guessing `-std=c++1?` - I expect troubles to surface once you build projects depending on root with a different c++ standard version than the one root got built with. – pseyfert Aug 01 '18 at 13:19

0 Answers0