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

标签 c++ boost c++-cli

我有一个 C++/CLI 命令行客户端,我正在尝试导入一个 native C++ 库,该库又具有 #include <boost/asio.hpp> .

当我尝试导入它时,出现以下错误:

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

includes 必须位于静态库的 header 中,因为它们是成员变量。

那么从静态/ native 库导入和使用这些类的最简单选项是什么?

最佳答案

这个问题已经出现在boost trac上,你可以找到它here .目前的解决方案(由 Michael Rasmussen 提供)是这样做的

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

并包装你的 boost includes,它们在那些 ifdefs 中有通用符号的问题。

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

关于c++ - 如何将使用 boost::asio 的 native C++ 静态库导入 CLI/C++ 混合模式应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40505845/

相关文章:

C++ #include,嵌套包含如何工作?

c++ - 在 UML 中绘制智能指针

c++ - 使用 GCC 在 Linux 上 boost 链接

c++ - 使用 native 依赖项加载 clr 库

c++ - 给定一个数字打印下一个具有相同数量的最大数字

c++ - Arduino 上一次中断的多个触发器

.net - 如何在托管接口(interface)类中提供委托(delegate)

c# - C++/CLI库中的早期完成和内存泄漏

C++ 语法我不明白

c++ - boost::async_write 在写入一段时间后失败