0

I have a link error with undefined symbols, e.g.

undefined reference to `vtable for tbb::task'

My gcc options (passed through the mainwin mwdip wrapper) has the following section:

-lxerces-c -ltbb -lboost_chrono

When I include verbose output with -v , I see the following section in the verbose output:

-lxerces-c -lboost_chrono

Why would the verbose output skip some -l args?

Does gcc try to ignore libraries it thinks it doesn't need? Is there a way for me to force gcc to include a needed library that it is mistakenly thinking it can skip?

JDiMatteo
  • 12,022
  • 5
  • 54
  • 65
  • 1
    Copy-paste your command line (including -v) and output here? – Marc Glisse Mar 27 '15 at 22:02
  • I am not at liberty to copy and paste build commands from the proprietary software I work on. I realize it may be unreasonable to answer my question specifically due to this, but I hope at least the generic question "Does gcc try to ignore libraries it thinks it doesn't need" is answerable. – JDiMatteo Mar 27 '15 at 22:10
  • @JDiMatteo It depends on where you have placed the -ltbb on the command line. You need to place it after any other objects/static/shared libraries that references it - which is why seeing the exact command line that gets executed for the linking stage is very helpful. – nos Mar 27 '15 at 22:21

2 Answers2

1

GCC processes dependencies right-to-left. An undefined reference for a library that you're linking generally means that you're linking something that needs tbb after you linked tbb (and the linker doesn't go back and re-check tbb for the newly needed symbols).

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
  • Thanks, but this is not the problem. I've tried including -ltbb last and there are no circular dependencies on it. (I've also tried including it first, in the middle, and multiple times.) – JDiMatteo Mar 27 '15 at 22:42
  • @JDiMatteo - Other suggestions: add `-Wl,-t` to your linker command to make sure that the linker is using the `libtbb.so` you think it is. Run `nm -C --dynamic` on that `libtbb.so` to make sure it defines the symbols you think it does. – Josh Kelley Mar 28 '15 at 02:35
  • thanks for those suggestions. Please consider closing this as a duplicate of http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/29350920#29350920 – JDiMatteo Mar 30 '15 at 16:07
0

Some linker wrappers cannot handle linker scripts, so replace the libtbb.so linker script with a copy of libtbb.so.2 , e.g.

cp libtbb.so.2 libtbb.so

The libtbb.so file is an ASCII text file with this contents:

INPUT (libtbb.so.2)

This is a GNU ld linker script command. Some more complex builds may not support this. For example, if you include -v in the compiler options, you can see that the mainwin gcc wrapper mwdip discards linker script command files in the verbose output list of libraries to link in. A simple work around is to replace the linker script input command file with a copy of the file instead (or a symlink).

JDiMatteo
  • 12,022
  • 5
  • 54
  • 65