If I have some header with a template implementation:
#ifndef FOOHEADER_HPP
#define FOOHEADER_HPP
template <typename T>
struct Foo
{
void FooFun(){}
};
#endif
And two .cpp
-files which provides explicit instantiations of this declaration:
FloatFoo.cpp:
#include "FooHeader.hpp"
template struct Foo<float>;
IntFoo.cpp:
#include "FooHeader.hpp"
template struct Foo<int>;
I can compile the .cpp
-files to libraries IntFoo.so
and FloatFoo.so
.
The implementations will be used in an executable based on main.cpp
:
#include "FooHeader.hpp"
int main()
{
Foo<float> foo;
Foo<int> iFoo;
iFoo.FooFun();
foo.FooFun();
}
When compiling the executable:
clang++ main.cpp -L./ -lIntFoo -lFloatFoo
How do I know if the compiler actually used the instantiations in IntFoo,FloatFoo
, or if it instantiated new code implicitly from the initialization in main.cpp
?