Home:ALL Converter>Using LTO causes undefined reference to std::basic_string destructor

Using LTO causes undefined reference to std::basic_string destructor

Ask Time:2019-07-20T02:40:59         Author:C.M.

Json Formatter

Decided to try LTO in my build (CentOS 7, CMake 3.14.3, gcc 8.2.1, -std=c++17):

# this adds "-flto -fno-fat-lto-objects"
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)

All projects build fine, with exception of one:

/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(operation_context.cpp.o): In function `_GLOBAL__sub_I_operation_context.cpp':
operation_context.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_block_blob.cpp.o): In function `_GLOBAL__sub_I_cloud_block_blob.cpp':
cloud_block_blob.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_container.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_container.cpp':
cloud_blob_container.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_shared.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_shared.cpp':
cloud_blob_shared.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_ostreambuf.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_ostreambuf.cpp':
cloud_blob_ostreambuf.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_client.cpp.o):cloud_blob_client.cpp:(.text.startup+0x9c): more undefined references to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' follow
collect2: error: ld returned 1 exit status

For some mysterious reason libazurestorage.a provided by vcpkg (where it is built without LTO) can't resolve std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (and only that symbol!).

To make it even more interesting -- other projects that use libazurestorage.a build just fine. I've checked linker's cmdline -- they look practically identical (almost same set of libs, almost same order).

Any ideas what could be wrong? Or how to figure out why other projects build fine?

Author:C.M.,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57118064/using-lto-causes-undefined-reference-to-stdbasic-string-destructor
yy