We have built a C++ library using Boost and when we try to integrate the library in a binary we are having problem in linking because of “--instances=explicit” option used for building the binary.
The problem is, when we use --instances=explicit option (of Sun CC compiler) it expects us to instantiate the templates explicitly. As Boost internally uses templates when we use Boost with this option the linker is throwing “Undefined symbol” errors - which is expected as we are not instantiating the templates used in Boost explicitly.
Though I understand why the linker is throwing the error here, it looks tricky to instantiate all boost templates explicitly in the code. So, want to check if there any solution/workaround to use Boost with “-instances=explicit” option of Sun CC compiler.
Any help is much appreciated.
We can reproduce the problem with simple sample code as -
#include <iostream>
#include <boost/lexical_cast.hpp>
int main()
{
std::cout<<boost::lexical_cast<int>(“8”)<<std::endl;
}
With “--instances=explicit” option
Undefined first referenced
symbol in file
__type_0 boost::detail::lexical_cast<unsigned,std::string,false,char>(__type_0,__type_3*,unsigned) lexical.o
ld: fatal: Symbol referencing errors. No output written to a.out