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:
- https://gcc.gnu.org/onlinedocs/gcc-5.2.0/libstdc++/manual/manual/using_dual_abi.html
- Converting std::__cxx11::string to std::string
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.