3

I unfortunately am forced to use gcc 3.2.3 (MinGW) due to the 3rd party code base having issues with later versions of gcc.

With gcc 3.2.3, I can build a static library (yaml-cpp.a) just fine (by editing the CMakeLists.txt file to remove the 'set(LIB_TYPE SHARED)', but I can't link my application against the library. It always results in the following error:

C:/MinGW_2/bin/../lib/gcc-lib/mingw32/3.2.3/../../../libstdc++.a(c++locale.o)(.t ext+0x38c): undefined reference to `strtold'

I get the same error when trying to build a shared yaml-cpp library.

After searching the web for a bit, most seem to resolve this problem in their projects by using 'strtod' instead of 'strtold', but I can't find any reference to 'strtold' in the yaml-cpp code; so I'm at a bit of a loss?

Any ideas?

Gerry
  • 51
  • 3
  • I don't have access to gcc 3.2.3, but can you see if you can use `std::stringstream` and read in `long` s (or `long long` s)? For example, try `std::stringstream stream; stream << "5"; long n; stream >> n;` – Jesse Beder Dec 30 '10 at 02:08
  • Sure enough, that results in the exact same error. – Gerry Dec 30 '10 at 04:18

2 Answers2

2

I was able to get this to work by defining my own strtold which uses strtod:

#if (__MINGW32__) && (__GNUC__) && (__GNUC__ < 4)
extern "C" {
  long double strtold(const char *__restrict__ nptr, char **__restrict__ endptr) {
      return strtod(nptr, endptr);
  }
}
#endif

Admittedly, it's quite hacky, but it gets the job done. I wish I could check gcc's minor revision too, but this is sufficient for my environment where gcc 3.2.3 is the only version being used.

Gerry
  • 51
  • 3
0

It appears that internally, std::stringstream is calling strold. Unfortunately, this means that you can't switch it to strtod - you simply can't use that particular conversion.

Since yaml-cpp uses std::stringstream to do its conversion, I suggest removing the long-related conversions. In yaml-cpp/traits.h, remove the is_numeric specializations that have to do with long, such as:

template <> struct is_numeric <long double> { enum { value = true }; };
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
  • Thanks for the suggestion. I wound up removing every single reference to long in the project, and it still gives me the same error, after making clean and all. Does this make sense? Perhaps stringstream uses longs internally? – Gerry Dec 30 '10 at 16:12
  • Hmmm. Can you use `stringstream` in general? (for example, just declare a `std::stringstream` variable - will it link?) – Jesse Beder Dec 30 '10 at 16:32
  • Nope - sure can't. Same error. Sounds like I'm out of luck. – Gerry Dec 30 '10 at 16:35
  • Perhaps I can detect the version of gcc and implement my own strtold, which uses strtod? – Gerry Dec 30 '10 at 17:37