need to find out where the function is instantiated (gcc 4.7)

Viewed 104

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?

2 Answers

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
Related