boost serialization undefined reference

This question already has an answer here:

  • What is an undefined reference/unresolved external symbol error and how do I fix it? 27 answers

  • Actually, an edit to the question would be nice, but, I think I have an idea bout what going on : It looks like you are trying to separately compile a function template.

    This meaning that you are doing the following :

    g++ ScenarioResult.cpp -lboost_serialization
    

    which is throwing the error.

    ScenarioResult::serialize is a template function , meaning that it gets instantiated on the basis of the types of the template parameters that get passed to is. So, when compiling, the compiler doesn't know exactly the type, thus cannot generate the code.

    A quick fix would be to move the implementation of your serialize method into the header file of the class . Or, explicitly instansiate it in the cpp file as the following :

    void ScenarioResult::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive &ar, const unsigned int);
    
    链接地址: http://www.djcxy.com/p/62920.html

    上一篇: cython memoryview比预期慢

    下一篇: boost序列化未定义的参考