简体   繁体   中英

boost serialization linker error when defining NDEBUG

I'm having problems in my 'release' build of my project when linking with boost::serialization . The only real difference between my 'debug' and 'release' build is I defined DEBUG and use -O0 in debug and I defined NDEBUG and use -O3 in release.

I can compile, link and run totally fine in debug mode.

However, when I compile with release mode, it will compile fine but fail during linking with the following error:

/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.

I don't understand this, as the methods in question are fully defined. I don't do any sort of #ifdef NDEBUG , etc. macros in my code in these classes.

Does anyone understand why this might happen?

My Texture2D class :
Texture2D.hpp
Texture2D.cpp

My TextureManager class :
TextureManager.hpp
TextureManager.cpp

I'm happy to give more direct/localized code snippets if that would help.

Update : If I move the definition for the serialize methods into the header files, suddenly it links! I imagine this has to do with them being template methods, but I still don't understand why my 'debug' build works but my 'release' build doesn't...

Indeed it's because of that. Apparently in DEBUG builds, the template instantiations get external linkage (this is unusual with optimizations enabled since most likely the (toplevel) calls can be inlined.

See also

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM