我有一个 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/