使用 OpenWRT 工具链为 OpenWRT Linux 环境交叉编译 POCO 库

Cross-compiling the POCO library for OpenWRT Linux environment using the OpenWRT toolchain

我正在尝试使用 OpenWRT 工具链为 OpenWRT Linux 环境交叉编译 POCO 源包。我已经下载了 POCO 源码包并尝试交叉编译它,但是我得到如下错误日志

src/Error.cpp: In static member function 'static std::string
Poco::Error::getMessage(int)': src/Error.cpp:71:55: error: invalid
conversion from 'int' to 'const char*' [-fpermissive]
return std::string(strerror_r(errorCode, errmsg, 256));
                                                       ^
In file included from
/home/ubuntu/subhendu/options_cg/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.10/mips-openwrt-linux-musl/include/c++/4.8.3/string:53:0,
                 from include/Poco/Bugcheck.h:24,
                 from include/Poco/Foundation.h:148,
                 from src/Error.cpp:17: /home/ubuntu/subhendu/options_cg/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.10/mips-openwrt-linux-musl/include/c++/4.8.3/bits/basic_string.tcc:212:5:
error:   initializing argument 1 of 'std::basic_string<_CharT,
_Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' [-fpermissive]
     basic_string<_CharT, _Traits, _Alloc>::
     ^
/home/ubuntu/subhendu/Poco/poco-1.6.0/build/rules/compile:53: recipe for target
'/home/ubuntu/subhendu/Poco/poco-1.6.0/Foundation/obj/Linux/x86_64/debug_shared/Error.o'
failed make[1]: ***
[/home/ubuntu/subhendu/Poco/poco-1.6.0/Foundation/obj/Linux/x86_64/debug_shared/Error.o]
Error 1 make[1]: Leaving directory
'/home/ubuntu/subhendu/Poco/poco-1.6.0/Foundation' Makefile:69: recipe
for target 'Foundation-libexec' failed make: *** [Foundation-libexec]
Error 2

如果有人遇到同样的问题或对如何解决它有任何想法,请提供您的解决方案...

看着the man page for strerror_r,我明白了:

int strerror_r(int errnum, char *buf, size_t buflen);
            /* XSI-compliant */
char *strerror_r(int errnum, char *buf, size_t buflen);
            /* GNU-specific */

注意 return 类型的区别。

查看您的错误消息:

error: invalid conversion from 'int' to 'const char*' [-fpermissive]
return std::string(strerror_r(errorCode, errmsg, 256));
                                                       ^

您正在编译的源代码似乎期待 strerror_r 的 GNU 特定版本,但 正在获取 XSI 兼容的。您的目标没有提供 GNU 扩展,或者您的工具链设置不正确。

手册页继续:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)): The XSI-compliant version of strerror_r() is provided if:

(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE

Otherwise, the GNU-specific version is provided.

所以您可能想朝那个方向进行调查。 (当您尝试编译时,_POSIX_C_SOURCE_XOPEN_SOURCE_GNU_SOURCE 设置的是什么?)