0

I have been trying to learn Boost.Locale Module. Consider this example. The code gets successfully compiled but when I try to run it, it gives the error

Unhandled exception at 0x74d34b32 in LearningCPP.exe: Microsoft C++ exception: std::bad_cast at memory location 0x00a6fa48..

I have attached the stack-trace of the program also. Here it is:

    KernelBase.dll!74d34b32()   
    [Frames below may be incorrect and/or missing, no symbols loaded for KernelBase.dll]    
    KernelBase.dll!74d34b32()   
>   msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine)  Line 302 + 0x1d bytes  C++
    msvcr100d.dll!malloc(unsigned int nSize)  Line 56 + 0x15 bytes  C++
    LearningCPP.exe!std::use_facet<boost::locale::converter<char> >(const std::locale & _Loc)  Line 526 C++
    LearningCPP.exe!boost::locale::to_upper<char>(const char * str, const std::locale & loc)  Line 225 + 0x9 bytes  C++
    LearningCPP.exe!main()  Line 170 + 0xc4 bytes   C++
    LearningCPP.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes  C
    LearningCPP.exe!mainCRTStartup()  Line 371  C
    kernel32.dll!75268543()     
    ntdll.dll!776bac69()    
    ntdll.dll!776bac3c()    

Did anyone faced this issue when using Boost.Locale in Visual Studio 2010? If so, how do I resolve this issue?

PS: I have used option Use Unicode Character Set under the Character Set option of Visual Studio. I believe the libraries are correctly linked too.

Mahadeva
  • 1,584
  • 4
  • 23
  • 56
  • I have provided the link in question. It is official boost example entitled `conversions.cpp`. – Mahadeva Mar 21 '15 at 17:53
  • I run the example code on g++ 4.9.2 and it compiles and runs fine - without any crash. – szulak Mar 21 '15 at 17:57
  • 1
    It didn't worked in Visual Studio 2010. That is what the question is about. – Mahadeva Mar 21 '15 at 17:59
  • Probably unrelated, but have you seen the warning in this sample: http://www.boost.org/doc/libs/1_57_0/libs/locale/doc/html/wconversions_8cpp-example.html – sehe Mar 21 '15 at 21:50
  • Also interesting: [I fixed it - for anyone, who might step into the same trouble here is the solution: Although I didn't get any error message while compiling nor when the application was executed it was not sufficient to just include icuucd.lib for linking you have to include icuind.lib as well. Then you get the same result on Windows and Linux. – Rainer Mar 15 '14 at 9:31](http://stackoverflow.com/questions/22331487/string-conversion-with-boost-locale-different-behaviour-on-windows-and-linux#comment34094746_22345765) – sehe Mar 21 '15 at 21:53
  • The problem was related with all the examples, including the ones using widestring. The file was saved with option `Unicode (UTF-8 with signature) Codepage 65001`. Even in that option, it failed. – Mahadeva Mar 22 '15 at 02:12

1 Answers1

0

For others who may face the same issue, I found the solution. The program still faced error in this example ran for calendar.cpp, collate.cpp and `conversions.cpp from this link.

The solution was to add BOOST_ALL_DYN_LINK in preprocessor under Configuration Properties \ C/C++ \ Preprocessor. The program was able to run afterwards.

PS: In linker I had added boost_locale-vc100-mt-gd-1_55.lib.

Mahadeva
  • 1,584
  • 4
  • 23
  • 56