Bug #2743
closed
error: 'to_string' is not a member of 'std' when cross-compiling NFD for OpenWRT
Added by Mathias Gibbens over 9 years ago.
Updated over 9 years ago.
Description
Today I was working on cross-compiling NFD 0.3.1 for OpenWRT. When I do, I get this error (after fixing a different issue reported in bug #2299):
../tools/ndn-autoconfig/base-dns.cpp: In member function 'std::string ndn::tools::autoconfig::BaseDns::parseSrvRr(const ndn::tools::autoconfig::BaseDns::QueryAnswer&, int)':
../tools/ndn-autoconfig/base-dns.cpp:163:14: error: 'to_string' is not a member of 'std'
uri.append(std::to_string(convertedPort));
I found a similar issue in another project at https://bitbucket.org/fenics-project/dolfin/commits/066b8cfe, and changing std::to_string
to boost::lexical_cast<std::string>
seems to fix the problem.
Opinions?
- Target version set to Unsupported
This also affects ./rib/fib-updater.cpp
in NFD's master branch.
While waiting for uClibc to be updated, would there be any issues stopping us from switching to the boost function? NFD is already pulling in those libraries so there wouldn't be any extra dependencies and doing so would help ensure that the NFD code compiles nicely in many different environments.
In many places, I personally tried to reduce use of boost::lexical_cast
, as it is suppose to be slower than to_string
. I would suggest that we better add an emulation of to_string
specifically for uClibc platform (and may be some others).
I would suggest that we better add an emulation of to_string
specifically for uClibc platform (and may be some others).
It's unnecessary to use platform-specific emulation.
Instead, detect this feature in .waf-tools/compiler-features.py
, and fallback to boost::lexical_cast<std::string>
if std::to_string
isn't detected.
I disagree with this. Having dependent code (I'm assuming you're suggesting ifdefs all over the place) makes implementation cumbersome...
So. Either we do emulation, figure out flags to allow gcc on these platforms to expose to_string
, or fall back to lexical_cast
(this would be my last resort).
@Mathias. We have to_string
in a few other places. All of them cause the error or the compilation simply stopped at the first error?
I'm assuming you're suggesting ifdefs all over the place
You misunderstood note-4.
#ifdef
appears only in common.hpp
, which enables:
namespace std {
template<typename V>
std::string
to_string(const V& v)
{
return boost::lexical_cast<std::string>(v);
}
} // namespace std
The point is, emulation is enabled as a result of feature detection, not as a result of library version detection.
@Alex, I did a grep
to find where ever std::to_string
was used in the NFD code. In the current master there are only two occurrences. The build stops at the first one, but either of them will cause the error.
@Junxiao, I like your proposed solution.
- Status changed from New to In Progress
- Assignee set to Alex Afanasyev
Yes, I misunderstood what you were suggesting. +1 to the proposal.
- Status changed from In Progress to Code review
- % Done changed from 0 to 100
I can confirm that the patch works and resolves compilation error I was getting before. Thanks!
- Status changed from Code review to Closed
- Related to Bug #3303: error: 'to_string' is not a member of 'std' when cross-compiling ndn-cxx for OpenWRT added
Also available in: Atom
PDF