HarmonyOS鸿蒙Next中ohos5.0.1/boost1.87的编译问题_在ubuntu20上报错 error: '__declspec' attributes are not enabled; use -fdeclspec' or -fms-extensions

HarmonyOS鸿蒙Next中ohos5.0.1/boost1.87的编译问题_在ubuntu20上报错 error: ‘__declspec’ attributes are not enabled; use -fdeclspec’ or -fms-extensions 完整标题(标题字符限制120):

ohos5.0.1/boost1.87的编译问题_在ubuntu20上报错 error: ‘__declspec’ attributes are not enabled; use -fdeclspec’ or -fms-extensions’ to enable support for declspec attributes extern “c” declapec(dllimport) void stdcall LeaveCriticalSection(: RTL_CRITICAL_SECTION *)

cmake细节:

在ohos5.0 ubuntu20的虚拟机上编译带cmake版的boost1.87

cke_10435.png

问题截图如下,并且ohos5.0上不支持LeaveCriticalSection,目前有人尝试过?

cke_553.png

cke_217.png


更多关于HarmonyOS鸿蒙Next中ohos5.0.1/boost1.87的编译问题_在ubuntu20上报错 error: '__declspec' attributes are not enabled; use -fdeclspec' or -fms-extensions的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

开发者您好,可以采取以下方式解决:

经验证lycium上存在boost编译解决方案,可直接编译出boost 1.81静态库版本,如果您对1.87版本要求强烈,可以修改boost目录进行适配, 该解决方案去除了log,python,locale能力。

【解决方案】

使用lycium工具交叉编译OpenCV三方库等三方开源库,lycium交叉编译链接参考

【常见FAQ】

Q:HarmonyOS是否支持OpenCV的集成,有相关三方库文档链接吗?

A:开发者您好,请参考以下三方库文档:tpc_c_cplusplus

Q:编译OpenCV卡死如何解决?

A:MAKE默认会开启32个线程会导致线程阻塞,可以通过make指定线程数去编译,编译OpenCV卡死链接参考

更多关于HarmonyOS鸿蒙Next中ohos5.0.1/boost1.87的编译问题_在ubuntu20上报错 error: '__declspec' attributes are not enabled; use -fdeclspec' or -fms-extensions的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


我觉得你这是cmake配置, 误以为是win32的原因, __declspec 是不是vc++ 特有的?

是的,可我在cmake中把win32及win64都关闭了,同时明确为Linux仍不能正确地识别为linux,

编译错误因鸿蒙Next的ohos5.0.1/boost1.87组件使用了MSVC特性。Ubuntu环境下需在编译配置中启用Clang/GCC的兼容标志。具体操作:在编译脚本或CMakeLists.txt中添加-fdeclspec-fms-extensions参数以支持跨平台属性声明。检查NDK工具链版本是否匹配鸿蒙SDK要求。

这个错误是因为在Ubuntu环境下编译Windows特有的__declspec语法导致的。问题出现在Boost库尝试调用Windows API函数LeaveCriticalSection,而HarmonyOS Next的编译环境不支持这类Windows特定语法。

解决方案:

  1. 检查Boost配置,确保未启用Windows特定模块(如thread库的Win32后端)
  2. 在CMake配置中添加编译选项:-fms-extensions来支持declspec语法
  3. 或者修改Boost配置,强制使用POSIX线程库而非Win32版本

由于HarmonyOS基于Linux内核,应使用POSIX线程接口而非Windows临界区函数。建议重新配置Boost构建,禁用Windows特定功能:

./b2 threading=posix

如果问题持续,需要检查代码中是否直接或间接引用了Windows API,这在跨平台编译到HarmonyOS时是不兼容的。

回到顶部