boost :: filesystem :: copy_file()在c ++ 11中缺少符号 [英] boost::filesystem::copy_file() missing symbol in c++11

查看:443
本文介绍了boost :: filesystem :: copy_file()在c ++ 11中缺少符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Boost编译时没有 C ++ 11支持,则boost::filesystem使用模拟范围的枚举器.如果您随后使用此内置Boost并在具有C ++ 11支持的项目中使用它,则由于boost::filesystem::copy_file()的声明已更改,您最终会丢失符号.

If Boost is compiled without C++11 support the boost::filesystem uses emulated scoped enumerators. If you then take this built Boost and use it in a project with C++11 support you end up with a missing symbol because the declaration of boost::filesystem::copy_file() has changed.

有一个简单的解决方法:

There is an easy fix for this:

# 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版本定义BOOST_NO_SCOPED_ENUMSBOOST_NO_CXX11_SCOPED_ENUMS,包括boost/filesystem,如果以前没有定义,则将其再次删除(为安全起见)

This preprocess bit defines either the BOOST_NO_SCOPED_ENUMS or BOOST_NO_CXX11_SCOPED_ENUMS depending on the Boost version, includes boost/filesystem and then removes it again if it wasn't defined before (to be safe)

现在,这里的问题是,当我们为C ++ 11编译时,作用域枚举器已关闭:

Now the issue here is that the scoped enumerators are turned off when we are compiling for C++11:

# if __cplusplus >= 201103L
#   define NO_SCOPED_ENUMS
# endif

但是,如果Boost实际上是使用C ++ 11支持的编译的,则它将再次中断,因为声明将被更改.它必须是这样的:

However, if Boost has actually been compiled with C++11 support this will break again because the declaration will be changed. It needs to be something like:

// 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支持下编译吗?

我最近的

无论如何运行配置脚本,完成后都会在<boost-root>/libs/config/目录中找到一个新的头文件-user.hpp-. 请注意,默认情况下,configure不会将此标头安装到您的增强包含路径中.该标题包含配置脚本生成的所有选项,以及标题部分,其中包含默认版本(位于/boost/config/下)的用户可设置选项.

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破坏了二进制兼容性,尽管在大多数情况下某些情况下可能会奏效,但在某些时候会刺痛您.

You don't want to link a C++11 project with non-C++11 libraries. C++11 breaks binary compatibility and while things may work in most cases, it will bite you in the butt at some point.

另请参见我们是否需要使用c ++ 11重新编译库?

这篇关于boost :: filesystem :: copy_file()在c ++ 11中缺少符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆