1

I am currently experiencing linker errors that involve types in the std::__cxx11 namespace.

Here is my code:

#include <iostream>
#include <boost/locale.hpp>

int main()
{
    std::wstring text = L"Coucou";

    std::string latin1 = boost::locale::conv::from_utf(text, "Latin1");

    return 0;
}

Here is the error I have :

19:31:13 **** Incremental Build of configuration Debug for project tests_boost_asio ****
Info: Internal Builder is used for build
g++ "-IC:\\Program Files (x86)\\boost\\boost_1_69_0" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\tests_boost_asio.o" "..\\src\\tests_boost_asio.cpp" 
In file included from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:22,
                 from ..\src\tests_boost_asio.cpp:10:
C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/localization_backend.hpp:109:18: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
             std::auto_ptr<localization_backend> get() const;
                  ^~~~~~~~
In file included from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_conv.h:41,
                 from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/locale:43,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary/facets.hpp:17,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary.hpp:12,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:11,
                 from ..\src\tests_boost_asio.cpp:10:
C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:22,
                 from ..\src\tests_boost_asio.cpp:10:
C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/localization_backend.hpp:116:59: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
             void add_backend(std::string const &name,std::auto_ptr<localization_backend> backend);
                                                           ^~~~~~~~
In file included from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_conv.h:41,
                 from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/locale:43,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary/facets.hpp:17,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary.hpp:12,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:11,
                 from ..\src\tests_boost_asio.cpp:10:
C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:24,
                 from ..\src\tests_boost_asio.cpp:10:
C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/util.hpp:180:28: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
     BOOST_LOCALE_DECL std::auto_ptr<base_converter> create_utf8_converter();
                            ^~~~~~~~
In file included from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_conv.h:41,
                 from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/locale:43,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary/facets.hpp:17,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary.hpp:12,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:11,
                 from ..\src\tests_boost_asio.cpp:10:
C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:24,
                 from ..\src\tests_boost_asio.cpp:10:
C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/util.hpp:188:28: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
     BOOST_LOCALE_DECL std::auto_ptr<base_converter> create_simple_converter(std::string const &encoding);
                            ^~~~~~~~
In file included from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_conv.h:41,
                 from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/locale:43,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary/facets.hpp:17,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary.hpp:12,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:11,
                 from ..\src\tests_boost_asio.cpp:10:
C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:24,
                 from ..\src\tests_boost_asio.cpp:10:
C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/util.hpp:203:59: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
     std::locale create_codecvt(std::locale const &in,std::auto_ptr<base_converter> cvt,character_facet_type type);
                                                           ^~~~~~~~
In file included from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_conv.h:41,
                 from C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/locale:43,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary/facets.hpp:17,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale/boundary.hpp:12,
                 from C:\Program Files (x86)\boost\boost_1_69_0/boost/locale.hpp:11,
                 from ..\src\tests_boost_asio.cpp:10:
C:/mingw/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
g++ -o tests_boost_asio.exe "src\\tests_boost_asio.o" 
src\tests_boost_asio.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<wchar_t>(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)':
C:/Program Files (x86)/boost/boost_1_69_0/boost/locale/encoding.hpp:84: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<wchar_t>(wchar_t const*, wchar_t const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)'
collect2.exe: error: ld returned 1 exit status

19:31:14 Build Failed. 1 errors, 5 warnings. (took 1s.286ms)

According to my research, the warnings I have are normal.

The error is the following lines:

g++ -o tests_boost_asio.exe "src\\tests_boost_asio.o" 
src\tests_boost_asio.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<wchar_t>(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)':
C:/Program Files (x86)/boost/boost_1_69_0/boost/locale/encoding.hpp:84: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<wchar_t>(wchar_t const*, wchar_t const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)'
collect2.exe: error: ld returned 1 exit status

My compiler : mingw-w64 (version: 4.3)

My version of boost : 1.70.0

The version of GCC I used to compile boost : 8.1.0

Note that the problem is known and described on the following pages:

According to the links, I am probably trying to link together objects that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. “This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.”

What I tried :

  • I tried to define the following macro before including any standard library header : #define _GLIBCXX_USE_CXX11_ABI 0

If I set this macro to 0, I get an other error :

19:48:01 **** Incremental Build of configuration Debug for project tests_boost_asio ****
Info: Internal Builder is used for build
g++ -o tests_boost_asio.exe "src\\tests_boost_asio.o" 
src\tests_boost_asio.o: In function `std::string boost::locale::conv::from_utf<wchar_t>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::string const&, boost::locale::conv::method_type)':
C:/Program Files (x86)/boost/boost_1_69_0/boost/locale/encoding.hpp:84: undefined reference to `std::string boost::locale::conv::from_utf<wchar_t>(wchar_t const*, wchar_t const*, std::string const&, boost::locale::conv::method_type)'
collect2.exe: error: ld returned 1 exit status

19:48:01 Build Failed. 1 errors, 0 warnings. (took 162ms)

This error would suggest that the function is not defined in Boost, which I do not understand because Eclipse does not find any problem and I find examples like this on the internet. And anyway, it does not really solve the problem. It would force me to use the old ABI.

If I set this macro to 1, I still have the first error.

Note that I also tried to define this macro directly in the compiler options.

I also tried to recompile Boost with other options :

b2 cxxflags="-std=c++11" define=_GLIBCXX_USE_CXX11_ABI=1 install -j5 --toolset=gcc

It makes no difference.

Nothing works. I am a bit lost. I suspect mingw-w64 to be responsible for this.

I could also try to change the compiler but if I understood correctly, mingw is particularly suitable if I wish that my programs work as well under Windows as under Linux ? I often develop on Windows but it is imperative that my program runs on Linux.

Do you have any idea of what I can do to solve this problem ?

Thank you very much for your help.

Daily45
  • 19
  • 1
  • 1
    Looks like your 1st `g++` command is missing `-std=c++11` (or 14 or 17). So g++ is defaulting to some earlier version. – Richard Critten May 06 '19 at 18:08
  • Thank you for your help. It didn't works. Still have the first error. I used : g++ "-IC:\\Program Files (x86)\\boost\\boost_1_69_0" -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -o "src\\tests_boost_asio.o" "..\\src\\tests_boost_asio.cpp" – Daily45 May 06 '19 at 18:20
  • `Boost.Locale` is not a header only library and I don't see your `g++` command linking with the Boost libraries. Source: https://www.boost.org/doc/libs/1_70_0/more/getting_started/windows.html#header-only-libraries – Richard Critten May 06 '19 at 19:38

1 Answers1

0

I solved this problem on Linux g++ 9.2.0 with the following command:

g++ -D_GLIBCXX_USE_CXX11_ABI=0 -lboost_locale -o boost ./boost.cpp

It couldn't find from_utf function in boost because you didn't add the library to the linker. I also had a mixture of compilers: boost was compiled with gcc 5.5.0.

user4035
  • 22,508
  • 11
  • 59
  • 94