Menu

Why the boost namespace

AmanJiang
2014-11-03
2014-11-24
  • AmanJiang

    AmanJiang - 2014-11-03

    I am using dlib 18.8 and boost 1.55 together in a project,
    for some reason today I updated boost library to 1.56,
    and there were some error messages on compile time,
    it's about the redefinition of boost::noncopyable_::noncopyable.

    Although I noticed there is a macro called
    "BOOST_NONCOPYABLE_HPP_INCLUDED" in this header file
    which could be used to prevent this redefinition, but I have no
    idea why not just use a dlib namespace ?

     
    • Davis

      Davis - 2014-11-03

      Yeah, that's a problem with the newer boost and it will be fixed in the
      next dlib release. But to fix it, you can do just what you said, put
      noncopyable into the dlib namespace and remove the references to boost. So
      if you changed the file to this it will work fine:

      #ifndef DLIB_BOOST_NONCOPYABLE_HPP_INCLUDED
      #define DLIB_BOOST_NONCOPYABLE_HPP_INCLUDED
      namespace dlib {
          class noncopyable {
          protected:
              noncopyable() {}
              ~noncopyable() {}
          private:  
              noncopyable(const noncopyable&);
              const noncopyable& operator=(const noncopyable&);
          };
      }
      #endif  // DLIB_BOOST_NONCOPYABLE_HPP_INCLUDED
      
       

      Last edit: Davis 2014-11-03
      • Don M

        Don M - 2014-11-05

        I discovered this same problem. But it seems to me that you just need to fix the incorrect boost protection macro name. There are currently two protections:

        #ifndef DLIB_BOOST_NONCOPYABLE_HPP_INCLUDED
        #define DLIB_BOOST_NONCOPYABLE_HPP_INCLUDED
        
        #ifndef BOOST_NONCOPYABLE_HPP_INCLUDED
        #define BOOST_NONCOPYABLE_HPP_INCLUDED
        

        The second one does not match the name used in boost, it should be BOOST_NONCOPYABLE_HPP. If you change this, then it will only compile one copy.

         
        • Davis

          Davis - 2014-11-05

          Yeah, that would fix it as well. However, changing it to not mention boost
          at all will prevent this problem from happening in the future when boost
          changes these preprocessor names.

          Cheers,
          Davis

           
  • Doug Slater

    Doug Slater - 2014-11-24

    I experienced this issue as well in dlib 18.8 when I moved from boost 1.55 to boost 1.57. Changing to dlib 18.11 resolved it, but there is a similar issue in dlib/enable_if.h.

    Changing the preprocessor definition BOOST_UTILITY_ENABLE_IF_HPP to BOOST_CORE_ENABLE_IF_HPP as it is now in boost/core/enable_if.h resolves these compiler errors.

    I bet would be be quite a chore to keep up with every boost namespace and preprocessor definition change.

     
    • Davis

      Davis - 2014-11-24

      Yeah, thanks for pointing this out as well. I'm just going to change these
      so the declarations are in the dlib namespace rather than reuse the boost
      files so this is not a problem in the future.

      Cheers,
      Davis

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.