BOOST_ERROR_ code_HEADER_ONLY没有通告的效果 [英] BOOST_ERROR_CODE_HEADER_ONLY does not have the advertised effect

查看:236
本文介绍了BOOST_ERROR_ code_HEADER_ONLY没有通告的效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我包括升压/系统/错误_ code.hpp (提高1.58),但不想链接到boost_system,而是有一个头,唯一的解决办法。我通过定义读 BOOST_ERROR_ code_HEADER_ONLY ,应该是可能的。但不幸的是,它并没有达到预期效果。我仍然获得提振::系统:: system_category链接错误()。

In my app I include boost/system/error_code.hpp (boost 1.58) but don't want to link to boost_system, but instead have a header-only solution. I read by defining BOOST_ERROR_CODE_HEADER_ONLY that should be possible. But unfortunately, it does not work as expected. I still get a linker error for boost::system::system_category().

我不知道这是否是应该在所有的如果是如何工作的。在升压头中的code是:

I wonder if that is supposed to work at all and if so how. The code in the boost header is:

# ifdef BOOST_ERROR_CODE_HEADER_ONLY
    inline const error_category &  system_category() BOOST_SYSTEM_NOEXCEPT;
    inline const error_category &  generic_category() BOOST_SYSTEM_NOEXCEPT;
#else
    BOOST_SYSTEM_DECL const error_category &  system_category() BOOST_SYSTEM_NOEXCEPT;
    BOOST_SYSTEM_DECL const error_category &  generic_category() BOOST_SYSTEM_NOEXCEPT;
#endif

和你可以看到有没有为system_category定义体()。这怎么能在所有的工作没有链接到一个lib?

and as you can see there is no body defined for system_category(). How can this work at all without linking to a lib?

更新:

在它是由包括我发现其间如该声明的主体定义(在升压/系统/详细信息/错误_ code.hpp 升压/系统/错误_ code.hpp 文件。不过它不会避免链接器错误。我在X code工作(LLVM C ++ 11 ),并定义了 BOOST_ERROR_ code_HEADER_ONLY 目标设置,如果该事项。

In the meantime I found where the body of that declaration is defined (in boost/system/detail/error_code.hpp which is included by the boost/system/error_code.hpp file. Still it does not avoid the linker errors. I'm working in XCode (llvm C++11) and have defined BOOST_ERROR_CODE_HEADER_ONLY in the target settings, if that matters.

推荐答案

我知道了一些尝试后工作。成功这里的关键是要包含头升压/系统/错误_ code.hpp 之前的任何其他code,它包含标题,那么,同 BOOST_ERROR_ code_HEADER_ONLY preprocessor符号直接定义之前包括,在CPP文件。包括在一个CPP文件,而不是,例如,它是必不可少的在precompiled头(stdafx.h中,* _ prefix.h等),因为它包含code,它只能在一个对象文件。定义 BOOST_ERROR_ code_HEADER_ONLY 在项目/目标水平可能会奏效过,但因为你只在你的整个项目需要这正是一次/目标更有意义来定义权你包括升压头前的第一次。

I got it to work after some experimenting. The key for success here is to include the header boost/system/error_code.hpp before any other code that includes that header as well, with the BOOST_ERROR_CODE_HEADER_ONLY preprocessor symbol defined directly before the include, in a cpp file. It is essential to include it in a cpp file and not, e.g. in a precompiled header (stdafx.h, *_prefix.h etc.) because it includes code, which only works in an object file. Defining BOOST_ERROR_CODE_HEADER_ONLY at project/target level might work too, but since you only need this exactly once in your entire project/target it makes more sense to defined that right before you include the boost header the first time.

如果你遵循这个规则,你也不会被重复的符号问题的影响,如果你有同样的 system_category() code在多个CPP可能发生文件。

If you follow this rule you will also not be affected by a duplicate symbol problem that may occur if you include the same system_category() code in multiple cpp files.

当您编译在释放模式的code,因为编译器会自动删除包含code(如果不是在CPP文件中使用),也有可能收到的问题。所以这是最好禁用优化它。不过,既然你不希望你的常规code,是有意义的创建一个自己的CPP文件,只为这完全包含和禁用优化该文件。这是我结束了最后。

You may still get problems when you compile your code in release mode, as the compiler may automatically remove the included code (if not used in that cpp file). So it's better to disable optimization for it. However, since you don't want that for your regular code, it makes sense to create an own cpp file just for this include and disable optimization for that file entirely. This is how I ended up finally.

这篇关于BOOST_ERROR_ code_HEADER_ONLY没有通告的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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