使用Sun Studio 12.5编译Boost 1.81.0 Chrono/Thread库失败求助
问题:Sun OS 5.10 Sparc下用Sun Studio 12.5编译Boost 1.81.0的Chrono/Thread库失败
问题背景
在Sun OS 5.10 Sparc环境下,使用Sun Studio 12.5编译器以C++11标准编译Boost 1.81.0的Chrono或Thread库时编译失败,其他Boost库使用相同编译选项可正常构建。
编译错误日志
"CC" -std=c++11 -m64 -xarch=sparc -mt -lCstd -xO4 -mt -erroff=%none -xldscope=hidden -m64 -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o "bin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden/future.o" "libs/thread/src/future.cpp" ...failed sun.compile.c++ bin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden/future.o... ...skipped <pbin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden>libboost_thread.a for lack of <pbin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden>pthread/thread.o... ...skipped <p/export/home/ramesh/compiled_library/boost_1_81_0/lib>libboost_thread.a for lack of <pbin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden>libboost_thread.a... ...skipped <pbin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden>libboost_thread-variant-static.cmake for lack of <pbin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden>libboost_thread.a... ...skipped <p/export/home/ramesh/compiled_library/boost_1_81_0/lib/cmake/boost_thread-1.81.0>libboost_thread-variant-static.cmake for lack of <pbin.v2/libs/thread/build/sun/release/address-model-64/link-static/threadapi-pthread/threading-multi/visibility-hidden>libboost_thread-variant-static.cmake... sun.compile.c++ bin.v2/libs/thread/build/sun/release/address-model-64/threadapi-pthread/threading-multi/visibility-hidden/pthread/thread.o "./boost/system/detail/error_condition.hpp", line 298: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 272: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 310: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 284: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 298: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 272: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 298: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 272: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 310: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 284: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 310: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_condition.hpp", line 284: Error: type is not a member of boost::system::detail::enable_if<0, void>. "./boost/system/detail/error_code.hpp", line 173: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/detail/error_code.hpp", line 190: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/detail/error_code.hpp", line 195: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/detail/error_code.hpp", line 200: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/detail/std_category_impl.hpp", line 62: Error: Too many initializers for bc. "./boost/system/detail/std_category_impl.hpp", line 67: Error: Too many initializers for bc. "./boost/system/detail/std_category_impl.hpp", line 75: Error: Too many initializers for bc. "./boost/system/errc.hpp", line 36: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/errc.hpp", line 42: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/system_error.hpp", line 38: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/system_error.hpp", line 38: Error: Too many initializers for code_. "./boost/system/system_error.hpp", line 41: Error: Too many arguments in cast to boost::system::error_code. "./boost/system/system_error.hpp", line 41: Error: Too many initializers for code_. Compilation aborted, too many Error messages.
使用的编译命令
./b2 install address-model=64 runtime-link=shared "cflags=-std=c++11 linkflags=-std=c++11" threading=multi toolset=sun --prefix=/export/home/ramesh/compiled_library/boost_1_81_0/ --with-chrono
环境信息
- Sun OS: 5.10 Sparc
- Compiler: Sun Studio 12.5
解决方案
方案1:调整编译参数适配编译器
Sun Studio 12.5对C++11的SFINAE语法支持存在局限性,Boost 1.81.0的System库(Chrono/Thread依赖该库)代码触发了兼容性问题,可通过以下参数调整:
- 添加
BOOST_SYSTEM_NO_DEPRECATED宏,禁用System库中可能引发兼容问题的旧特性:
./b2 install address-model=64 runtime-link=shared "cflags=-std=c++11 linkflags=-std=c++11" threading=multi toolset=sun --prefix=/export/home/ramesh/compiled_library/boost_1_81_0/ --with-chrono define=BOOST_SYSTEM_NO_DEPRECATED
- 若上述命令仍报错,将
-std=c++11替换为Sun Studio专属的C++11启用标识-std=c++0x:
./b2 install address-model=64 runtime-link=shared "cflags=-std=c++0x linkflags=-std=c++0x" threading=multi toolset=sun --prefix=/export/home/ramesh/compiled_library/boost_1_81_0/ --with-chrono define=BOOST_SYSTEM_NO_DEPRECATED
方案2:降级Boost版本
Boost 1.81.0作为新版本,对旧编译器的兼容性较差。可尝试降级到Boost 1.76.0或更早版本,这些版本对Sun Studio 12.5的适配性更好,能避免上述编译错误。
方案3:手动修补Boost System库代码
针对报错的核心问题,直接修改Boost代码:
- 针对
enable_if相关错误:将boost::system::detail::enable_if替换为标准库的std::enable_if(需确保编译器支持该标准库特性),或改用Boost提供的enable_if_t别名简化写法; - 针对
error_code构造参数错误:检查boost/system/detail/error_code.hpp中的构造函数调用,确保参数数量与定义匹配,修正编译器误判的语法问题。
内容的提问来源于stack exchange,提问作者Thriveni
相关产品推荐
相关产品推荐

