开发者

Unable to build a usable yaml-cpp library (shared or static) with gcc 3.2.3 in Windows

开发者 https://www.devze.com 2023-02-01 12:13 出处:网络
I 开发者_StackOverflowunfortunately am forced to use gcc 3.2.3 (MinGW) due to the 3rd party code base having issues with later versions of gcc.

I 开发者_StackOverflowunfortunately 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?


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.


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 }; };
0

精彩评论

暂无评论...
验证码 换一张
取 消