Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't statically link Boost Locale #156

Open
Gab-Menezes opened this issue Mar 10, 2023 · 1 comment
Open

Can't statically link Boost Locale #156

Gab-Menezes opened this issue Mar 10, 2023 · 1 comment

Comments

@Gab-Menezes
Copy link

Trying to statically link Boost Locale with cmake returns an error.

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(main)

#set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS locale REQUIRED)
if(NOT Boost_FOUND)
    message(FATAL_ERROR "Some Boost libraries missing in the system")
endif()


add_executable(main main.cpp)
target_link_libraries(main ${Boost_LIBRARIES})

main.cpp

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

int main() {
    boost::locale::generator gen;
    std::locale loc1 = gen("pt_BR.UTF-8");
    return 0;
}

Dynamic linkage works fine but uncommenting set(Boost_USE_STATIC_LIBS ON) will result in an error.
The boost library was installed via package manager with sudo apt install libboost-all-dev.

As we can see in the prints I have Locale installed and also the icu stuff.
image
image

ldd of the binary if not statically linked.
image

I can statically link other boost libraries, but locale in specific gives me an error.

Output of the make command: log.txt

Ubuntu version: 20.04 and 22.04
Cmake version: >= 3.16
Boost version: 1.71 and 1.74
g++ version: 10.3 and 11.3

@Flamefire
Copy link
Collaborator

As the errors are all of "undefined reference to " you need to link to the ICU target. In particular icudata, icui18n, icuuc, e.g. by using find_package(ICU ...) and the targets ICU:data ICU::i18n ICU::uc

This is done automatically for shared libraries in general. Boost 1.75 config files add those dependencies too in all cases. So upgrading to Boost 1.75 or newer will also solve this.

Side note:

find_package(Boost COMPONENTS locale REQUIRED)

# This is redundant due to the above REQUIRED 
if(NOT Boost_FOUND)
    message(FATAL_ERROR "Some Boost libraries missing in the system")
endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants