Examples
I think I meet the same problem, here is an example:
/* A.cpp */
#include <iostream>
#include <string>
using UString = std::u32string;
void foo(const UString &ustr) {
std::cout << "hello" << '\n';
}
int main () {
UString ustr = U"xxxx";
foo(ustr);
}
# CMakeLists.txt for A.cpp
project(first_example)
set(CMAKE_CXX_STANDARD 17)
add_library(B B.cpp)
target_link_libraries(B)
Symbol of foo
in libA.a
is:
$ nm --demangle libA.a | grep foo
...
0000000000000000 T foo(std::__cxx11::basic_string<char32_t, std::char_traits<char32_t>, std::allocator<char32_t> > const&)
std::__cxx11::basic_string
is a new version of std::basic_string
, where the introduced namespace __cxx11
is designed for backwards compatibility. When libtorch
is included, it forces the project to link to the old version of standard library.
/* B.cpp */
#include <iostream>
#include <string>
using UString = std::u32string;
void foo(const UString &ustr) {
std::cout << "hello" << '\n';
}
int main () {
UString ustr = U"xxxx";
foo(ustr);
}
# CMakeLists.txt for B.cpp
project(first_example)
set(CMAKE_CXX_STANDARD 17)
find_package(Torch REQUIRED)
add_library(A A.cpp)
target_link_libraries(first "${TORCH_LIBRARIES}")
After building libB.a
, the symbol of foo
is:
$ nm --demangle libB.a | grep foo
...
0000000000000301 T foo(std::basic_string<char32_t, std::char_traits<char32_t>, std::allocator<char32_t> > const&)
If other libraries the project relied on are linked to std::__cxx11::
and the project is forced to link to old version, there will be tons of undefined reference
errors. Is there any way to solve this problem with lower cost ?
Environment
Note
If there is anything wrong, please feel free to edit.