如果 Boost 编译时没有 C++11 支持 boost::filesystem
使用模拟范围枚举器。如果您随后将这个构建的 Boost 并在支持 C++11 的项目中使用它,您最终会得到一个丢失的符号,因为 boost::filesystem::copy_file()
的声明已改变。
有一个简单的解决办法:
# if __cplusplus >= 201103L
# define NO_SCOPED_ENUMS
# endif
# ifdef NO_SCOPED_ENUMS
# if BOOST_VERSION < 105000
# ifndef BOOST_NO_SCOPED_ENUMS
# define BOOST_NO_SCOPED_ENUMS
# define REMOVE
# endif
# else
# ifndef BOOST_NO_CXX11_SCOPED_ENUMS
# define BOOST_NO_CXX11_SCOPED_ENUMS
# define REMOVE
# endif
# endif
# endif
# include "boost/filesystem.hpp"
# if defined(NO_SCOPED_ENUMS) && defined(REMOVE)
# undef REMOVE
# if BOOST_VERSION < 105000
# undef BOOST_NO_SCOPED_ENUMS
# else
# undef BOOST_NO_CXX11_SCOPED_ENUMS
# endif
# endif
此预处理位定义 BOOST_NO_SCOPED_ENUMS
或BOOST_NO_CXX11_SCOPED_ENUMS
根据 Boost 版本,包括 boost/filesystem
然后如果之前没有定义它,则再次删除它(为了安全)
现在的问题是,当我们编译 C++11 时,作用域枚举器被关闭:
# if __cplusplus >= 201103L
# define NO_SCOPED_ENUMS
# endif
但是,如果 Boost 实际上是使用 C++11 支持编译的,则这将再次中断,因为声明将被更改。它需要类似于:
// BOOST_COMPILED_WITH_CXX11 doesn't exist
# if (__cplusplus >= 201103L) && !defined(BOOST_COMPILED_WITH_CXX11)
# define NO_SCOPED_ENUMS
# endif
这就是我的问题所在:
tl;dr - 我可以确定 Boost 是否是使用 C++11 支持编译的吗?
我最接近的found是:
However you run the configure script, when it finishes you will find a new header -
user.hpp
- located in the<boost-root>/libs/config/
directory. Note that configure does not install this header into your boost include path by default. This header contains all the options generated by the configure script, plus a header-section that contains the user settable options from the default version of (located under /boost/config/).
最佳答案
您不想想要将 C++11 项目与非 C++11 库链接。 C++11 破坏了二进制兼容性,虽然在大多数情况下一切都可以正常工作,但在某些时候它会咬你的屁股。
关于c++11 中 boost::filesystem::copy_file() 缺少符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783790/