c++11 中 boost::filesystem::copy_file() 缺少符号

标签 boost c++11

如果 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_ENUMSBOOST_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 破坏了二进制兼容性,虽然在大多数情况下一切都可以正常工作,但在某些时候它会咬你的屁股。

另请参阅do we need to recompile libraries with c++11?

关于c++11 中 boost::filesystem::copy_file() 缺少符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783790/

相关文章:

c++ - CMake FindBoost.cmake MinGW-W64 : searching for library with incorrect name

c++ - boost::filesystem::native 路径的预期形式是什么?

c++ - 试图在类中使用 boost::spirit::qi 解析器的段错误

c++ - 如何向多个线程发送事件信号

c++ - 如何在集群上链接 boost 库?

c++ - std::future 或 std::shared_future 等待多线程

c++多个接口(interface)到同一功能模板

c++ - static_assert 如果声明了类型

c++ - 是否可以在已分配的内存上初始化 std::vector ?

c++ - C++11 中的非阻塞信号量?