Skip to content

[cmake] fixes static build for macos with OpenMP enabled (fixes #6601) - #6600

Merged
jameslamb merged 4 commits into
lightgbm-org:masterfrom
Mottl:macos_openmp_cmake_fix
Aug 15, 2024
Merged

jameslamb merged 4 commits into
lightgbm-org:masterfrom
Mottl:macos_openmp_cmake_fix

Conversation

@Mottl

@Mottl Mottl commented Aug 10, 2024 •

Copy link
Copy Markdown
Contributor

Fixes #6601 with -DBUILD_STATIC_LIB=ON on macos with USE_OPENMP enabled

@Mottl

Mottl commented Aug 10, 2024

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Mottl Mottl changed the title Fixes CMakeLists.txt for macos [cmake] fixes static build for macos with OpenMP enabled Aug 10, 2024
@StrikerRUS StrikerRUS added the fix label Aug 10, 2024

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this, and sorry for breaking builds of the static library on macOS. We probably need to add some CI coverage of that.

Could you please instead skip this entire block, by adding a NOT BUILD_STATIC_LIB into this condition?

https://github.com/microsoft/LightGBM/blob/9a76aae1b5979a455bf6d80728d2a88f36823380/CMakeLists.txt#L755

All of this logic, like modifying RPATH entries, should be unnecessary for the static library.

@Mottl

Mottl commented Aug 10, 2024

Copy link
Copy Markdown
Contributor Author

Thanks James. Done.

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

I pulled your branch onto my M2 mac and tested like this:

git remote add mottl git@github.com:Mottl/LightGBM.git
git fetch mottl macos_openmp_cmake_fix

cmake \
    -B build \
    -S . \
    -DBUILD_STATIC_LIB=ON \
    -DUSE_OPENMP=ON

cmake --build build --target all -j4

Saw everything build successfully, with 0 warnings or errors.

[ 89%] Built target lightgbm_objs
[ 97%] Linking CXX static library /Users/jlamb/repos/LightGBM/lib_lightgbm.a
[ 97%] Building CXX object CMakeFiles/lightgbm.dir/src/application/application.cpp.o
[ 97%] Building CXX object CMakeFiles/lightgbm.dir/src/main.cpp.o
[ 97%] Built target _lightgbm
[100%] Linking CXX executable /Users/jlamb/repos/LightGBM/lightgbm
[100%] Built target lightgbm

Also inspected the library a bit and everything looked correct.

ar -t ./lib_lightgbm.a
nm ./lib_lightgbm.a

@jameslamb jameslamb changed the title [cmake] fixes static build for macos with OpenMP enabled [cmake] fixes static build for macos with OpenMP enabled (fixes #6601) Aug 15, 2024
@jameslamb
jameslamb merged commit 047c4fd into lightgbm-org:master Aug 15, 2024
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build fails on macos with openmp and static lib enabled

3 participants