Linker errors under Linux on using locale in a tiny example - using my own boost build

i can't built a simple locale from_utf using example with my own build boost 1.84.0 [system] SUSE Tumbleweed gcc (SUSE Linux) 13.2.1 20240206 [revision 67ac78caf31f7cb3202177e6428a46d829b70f23] [boost build] using https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_... tar -xf boost_1_84_0.tar.bz2 cd boost_1_84_0 ./bootstrap.sh --prefix=/home/test/boost_1_84_0_install ./b2 install ---- [CMakeLists.txt] cmake_minimum_required (VERSION 3.14) project (MyTest) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) list(APPEND CMAKE_PREFIX_PATH "/home/test/boost_1_84_0_install/lib/cmake") find_package( Boost REQUIRED COMPONENTS locale ) add_executable( my_test main.cpp) target_link_libraries( my_test PRIVATE Boost::boost ) ---- [main.cpp] #include <boost/locale.hpp> int main() { auto x = boost::locale::conv::from_utf( "blun", "ISO-8859-1" ); return 0; } ---- build: _build>cmake ../MyTest _build>make [ 50%] Building CXX object CMakeFiles/my_test.dir/main.cpp.o [100%] Linking CXX executable my_test /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/my_test.dir/main.cpp.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<char>(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)': main.cpp:(.text._ZN5boost6locale4conv8from_utfIcEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKT_RKS8_NS1_11method_typeE[_ZN5boost6locale4conv8from_utfIcEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKT_RKS8_NS1_11method_typeE]+0x42): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<char>(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/my_test.dir/build.make:97: my_test] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/my_test.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 any idea what is happening here?

Dennis Luehring wrote: ...
find_package( Boost REQUIRED COMPONENTS locale ) add_executable( my_test main.cpp) target_link_libraries( my_test PRIVATE Boost::boost ) ... any idea what is happening here?
Since Locale is a compiled library, you need to link to Boost::locale. target_link_libraries( my_test PRIVATE Boost::boost Boost::locale )

On 3/20/24 23:07, Peter Dimov via Boost wrote:
Dennis Luehring wrote: ...
find_package( Boost REQUIRED COMPONENTS locale ) add_executable( my_test main.cpp) target_link_libraries( my_test PRIVATE Boost::boost ) ... any idea what is happening here?
Since Locale is a compiled library, you need to link to Boost::locale.
target_link_libraries( my_test PRIVATE Boost::boost Boost::locale )
What is the Boost::boost target?

Andrey Semashev wrote:
On 3/20/24 23:07, Peter Dimov via Boost wrote:
Dennis Luehring wrote: ...
find_package( Boost REQUIRED COMPONENTS locale ) add_executable( my_test main.cpp) target_link_libraries( my_test PRIVATE Boost::boost ) ... any idea what is happening here?
Since Locale is a compiled library, you need to link to Boost::locale.
target_link_libraries( my_test PRIVATE Boost::boost Boost::locale )
What is the Boost::boost target?
It's the (FindBoost) target for all header-only libraries. https://cmake.org/cmake/help/latest/module/FindBoost.html#imported-targets We call this Boost::headers, but Boost::boost is also defined for compatibility.

Am 20.03.2024 um 21:07 schrieb Peter Dimov via Boost:
Since Locale is a compiled library, you need to link to Boost::locale.
target_link_libraries( my_test PRIVATE Boost::boost Boost::locale )
thank your for solving it - i copied that Boost cmake stuff over from a big project which uses locale very often - but i did't found any Boost::locale used in this project which is based only on find_package(boost config ...) - maybe some other boost lib is grabbing the dependency automaticly in this project? thanks again
participants (3)
-
Andrey Semashev
-
Dennis Luehring
-
Peter Dimov