我正在尝试使用 uClibc 交叉编译一个程序,但在执行链接时,我总是收到一个错误,即未定义对 std::to_string 的引用。我已经应用了解决方法,这应该有助于解决这个问题:
#include <string>
#include <sstream>
template <typename T>
std::string to_string(T value)
{
std::ostringstream os ;
os << value ;
return os.str() ;
}
int main()
{
std::string perfect = to_string(5) ;
}
这在构建 CXX 对象的阶段有所帮助,但在链接时问题又回来了。
这是错误:
[ 76%] Linking CXX executable gateway
/home/jakub/build/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-
0.9.33.2_eabi/usr/lib/libPocoFoundation.so: warning: the use of OBSOLESCENT `utime' is discouraged, use
`utimes'
/home/jakub/build/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-
0.9.33.2_eabi/usr/lib/libcrypto.so.1.0.0: warning: gethostbyname is obsolescent, use getnameinfo() instead.
libGateway.a(NewDeviceCommand.cpp.o): In function `Gateway::NewDeviceCommand::toString() const':
NewDeviceCommand.cpp:(.text+0x218): undefined reference to `std::to_string(int)'
libGateway.a(DeviceManager.cpp.o): In function `Gateway::DeviceManager::lastValue(Gateway::DeviceID
const&, Gateway::ModuleID const&, Poco::Timespan const&)':
DeviceManager.cpp:(.text+0x554): undefined reference to `std::to_string(int)'
DeviceManager.cpp:(.text+0x57c): undefined reference to `std::to_string(unsigned long)'
libGateway.a(DeviceManager.cpp.o): In function
`Gateway::DeviceManager::responseDeviceList(Poco::Timespan const&,
Poco::AutoPtr<Gateway::Answer>)':
DeviceManager.cpp:(.text+0xc04): undefined reference to `std::to_string(unsigned long)'
DeviceManager.cpp:(.text+0xc2c): undefined reference to `std::to_string(unsigned long)'
DeviceManager.cpp:(.text+0xce0): undefined reference to `std::to_string(unsigned long)'
DeviceManager.cpp:(.text+0xd08): undefined reference to `std::to_string(unsigned long)'
....
感谢您的意见。