在与boost::serialization
关联时,我的项目“发布”版本出现问题。我的'debug'和'release'版本之间唯一真正的区别是我定义了DEBUG
并在调试中使用-O0
,我定义了NDEBUG
并在版本中使用-O3
。 / p>
我可以在调试模式下完全编译,链接和运行。
但是,当我使用发布模式进行编译时,它会正常编译,但在链接时会出现以下错误:
/home/jarrett/projects/icebreakers/glr/build/libglr.a(ModelManager.o): In function `serialize<boost::archive::text_iarchive, glr::models::Model>':
/home/jarrett/projects/icebreakers/glr/deps/boost/include/boost/serialization/access.hpp:118: undefined reference to `void glr::models::Model::serialize<boost::archive::text_iarchive>(boost::archive::text_iarchive&, unsigned int)'
/home/jarrett/projects/icebreakers/glr/build/libglr.a(ModelManager.o): In function `serialize<boost::archive::text_oarchive, glr::models::Model>':
/home/jarrett/projects/icebreakers/glr/deps/boost/include/boost/serialization/access.hpp:118: undefined reference to `void glr::models::Model::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int)'
/home/jarrett/projects/icebreakers/glr/build/libglr.a(TextureManager.o): In function `serialize<boost::archive::text_iarchive, glr::glw::Texture2D>':
/home/jarrett/projects/icebreakers/glr/deps/boost/include/boost/serialization/access.hpp:118: undefined reference to `void glr::glw::Texture2D::serialize<boost::archive::text_iarchive>(boost::archive::text_iarchive&, unsigned int)'
/home/jarrett/projects/icebreakers/glr/build/libglr.a(TextureManager.o): In function `serialize<boost::archive::text_oarchive, glr::glw::Texture2D>':
/home/jarrett/projects/icebreakers/glr/deps/boost/include/boost/serialization/access.hpp:118: undefined reference to `void glr::glw::Texture2D::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int)'
/home/jarrett/projects/icebreakers/glr/build/libglr.a(AnimationManager.o): In function `serialize<boost::archive::text_iarchive, glr::glw::Animation>':
/home/jarrett/projects/icebreakers/glr/deps/boost/include/boost/serialization/access.hpp:118: undefined reference to `void glr::glw::Animation::serialize<boost::archive::text_iarchive>(boost::archive::text_iarchive&, unsigned int)'
/home/jarrett/projects/icebreakers/glr/build/libglr.a(AnimationManager.o): In function `serialize<boost::archive::text_oarchive, glr::glw::Animation>':
/home/jarrett/projects/icebreakers/glr/deps/boost/include/boost/serialization/access.hpp:118: undefined reference to `void glr::glw::Animation::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int)'
collect2: error: ld returned 1 exit status
scons: *** [build/darkhorizon] Error 1
scons: building terminated because of errors.
我不明白这一点,因为所讨论的方法是完全定义的。我在这些类的代码中没有做任何类型的#ifdef NDEBUG
等宏。
有谁理解为什么会这样?
我的Texture2D类:
Texture2D.hpp
Texture2D.cpp
我的TextureManager类:
TextureManager.hpp
TextureManager.cpp
如果有帮助,我很乐意提供更多直接/本地化的代码段。
更新:如果我将serialize
方法的定义移到头文件中,突然它会链接!我想这与他们作为模板方法有关,但我仍然不明白为什么我的'debug'构建有效,但我的'release'版本没有......
答案 0 :(得分:1)
确实是因为这个原因。显然在DEBUG构建中,模板实例化获得外部链接(这在启用优化时很常见,因为很可能内联(顶级)调用。
另见