Reputation: 1534
I compile and link a third-party library with GCC 4.7.3. I try understand what triggers the undefined symbol error:
Undefined symbols for architecture x86_64:
"void MyObject::myFunction<....>(...) const", referenced from:
void NameSpace::AnotherFunction<some_particular_arguments>(...) in some_source.cc.o
NameSpace::AnotherFunction
is obviously sitting in some_source.cc
, but can I get some info from compiler/linker on where/who instantiate this function with some_particular_arguments
?
The build is done using CMake and there is NameSpace_AnotherFunction.inst
with template instantiations for the corresponding function, but this particular set of template arguments is not there.
Obviously there are no instantiations in some_source.cc
, otherwise i would not ask ;)
Thus I wonder if there is a way to get info on something like Point of Instantiation (or similar) for that particular template arguments list of the function AnotherFunction
?
Upvotes: 4
Views: 122
Reputation: 6287
One way to do it is to cause a compiler error (or better a warning) in the code that depends on the template type (so it is only emitted when the template is actually instantiated).
You can try making it more focused by doing something like
if constexpr (std::is_same_v<T, some_particular_argument>())
// code emitting warning
Upvotes: 0
Reputation: 30577
First compile with the -g flag to get an object file with source file and line number information for each symbol. Then use the nm command with -C and -l options on the object file to print out the symbol info, grepping for AnotherFunction. This should give you the line numbers.
Edit: Now that I have had a chance to try this out, I don't think it solves @Denis's problem. Unfortunately the line given is the line on which the function template is defined rather than the line on which it is instantiated. Leaving this answer here anyway in case it is useful to someone else...
Upvotes: 1