serializationboostswig

Undefined symbol for boost serialization extended type info when using swig to convert from C++ to tcl


Hi I'm writing the conversion from C++ to Tcl using Swig. Compiling is fine, everything is fine until I load the resulting shared library. It gives me error like this.

couldn't load file "./Library.so": ./Library.so: undefined symbol: _ZNK5boost13serialization13typeid_system27extended_type_info_typeid_012is_less_thanERKNS0_18extended_type_infoE

I've checked boost and this signature is in boost/serialization/extended_type_info.hpp. But I already added this in my Common.h section and include it throughout. Also I added -lboost_serialization during compilation but the issue doesn't go away. Weird thing is I write a cpp test and it works fine in C++ domain. I don't know what is going on. Would you please help?

Thank you,

Below is my Common.h:

#ifndef COMMON_H_
#define COMMON_H_

#include <cstddef>
#include <typeinfo>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctime>
#include <map>
#include <set>
#include <boost/variant.hpp>
#include <memory>
#include <boost/system.hpp>
#include <boost/filesystem.hpp>
#include <boost/preprocessor.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/variant.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/type_info_implementation.hpp>

#include <boost/serialization/config.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/serialization/extended_type_info.hpp>
#include <boost/serialization/extended_type_info_typeid.hpp>
#include <boost/config/abi_prefix.hpp>

#endif

Solution

  • There are two possible explanations.

    1. First is if the Dll doesn't dynamically link libboost_serialization.so (e.g. using -lboost_serialization).

    2. The second is if the version of the dynamic library found at runtime does not match the headers used when compiling.¹

    You can probably start diagnosing this by doing

    ldd lib_my_tcl_module.so
    

    ¹ Technically this might include different configurations of the same code, though a scan of the docs do not reveal any obvious flags/defines that could cause this. Nevertheless, check your compiler flags, especially anything related to RTTI