如何将使用boost::asio的本地c++静态库导入CLI/ c++混合模式应用程序?



我有一个c++/CLI命令行客户端,我正试图导入一个本地的c++库,它反过来又有#include <boost/asio.hpp>

当我尝试导入这个时,我得到以下错误:

2>C:boost_1_54_0boost/asio/generic/detail/endpoint.hpp(27): error C2059: syntax error : 'generic'
2>C:boost_1_54_0boost/asio/generic/detail/endpoint.hpp(27): error C2143: syntax error : missing ';' before '{'
2>C:boost_1_54_0boost/asio/generic/detail/endpoint.hpp(27): error C2447: '{' : missing function header (old-style formal list?)
2>C:boost_1_54_0boost/asio/generic/detail/impl/endpoint.ipp(32): error C2059: syntax error : 'generic'

include必须在静态库的头文件中,因为它们是成员变量。

那么从静态/本机库中导入和使用这些类的最简单的选择是什么呢?

这个问题已经出现在boost跟踪中,您可以在这里找到它。目前的解决方案(由Michael Rasmussen提供)是这样做的

#ifdef __cplusplus_cli
#define generic __identifier(generic)
#endif>
#include <boost/filesystem.hpp>
#ifdef __cplusplus_cli
#undef generic
#endif

和包装你的boost include,这些ifdef中的通用符号有问题。

编辑:我错过了关于你的库是一个静态库的一点,你可能想使用动态boost库,它可以避免多个符号被定义的问题。使用BOOST_ALL_DYN_LINK预处理器定义来使用boost dll。

最新更新