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

LightGBM is incompatible with older versions of CMake #5642

Closed
jameslamb opened this issue Dec 21, 2022 · 1 comment · Fixed by #6260
Closed

LightGBM is incompatible with older versions of CMake #5642

jameslamb opened this issue Dec 21, 2022 · 1 comment · Fixed by #6260

Comments

@jameslamb
Copy link
Collaborator

jameslamb commented Dec 21, 2022

Description

LightGBM's CMakeLists.txt claims that it supports cmake>=3.0.

cmake_minimum_required(VERSION 3.0)

However, I found that it CMake==3.10.2 is unable to generate Makefiles with the project's current setup.

Reproducible example

docker run \
    --rm \
    --entrypoint="" \
    -it ubuntu:18.04 \
    /bin/bash

apt-get update -y
apt-get install -y --no-install-recommends \
    build-essential \
    ca-certificates \
    cmake \
    curl \
    git \
    sudo \
    wget

cd /usr/local/src
git clone \
    --recursive \
    https://github.com/microsoft/LightGBM.git

cd ./LightGBM

# 3.10.2
cmake --version

mkdir build
cd build
cmake -DUSE_OPENMP=OFF ..

Results in the following errors.

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
...
-- Using _mm_malloc
CMake Error at CMakeLists.txt:436 (target_link_libraries):
  Target "lightgbm_objs" of type OBJECT_LIBRARY may not be linked into
  another target.  One may link only to STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

You have called ADD_LIBRARY for library _lightgbm without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Error at CMakeLists.txt:454 (target_link_libraries):
  Target "lightgbm_capi_objs" of type OBJECT_LIBRARY may not be linked into
  another target.  One may link only to STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

CMake Error at CMakeLists.txt:454 (target_link_libraries):
  Target "lightgbm_objs" of type OBJECT_LIBRARY may not be linked into
  another target.  One may link only to STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

Upgrading cmake to the latest release (v3.25.1), LightGBM can be compiled successfully.

apt-get remove -y --purge \
    cmake

wget \
    https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.sh

sudo mkdir /opt/cmake
sudo sh cmake-3.25.1-linux-x86_64.sh --prefix=/opt/cmake
cp /opt/cmake/bin/cmake /usr/bin

# 3.25.1
/usr/local/bin/cmake --version

cd /usr/local/src/LightGBM
rm -r ./build
mkdir ./build
cd ./build
/usr/local/bin/cmake -DUSE_OPENMP=OFF ..
make -j2

Environment info

LightGBM version or commit hash: a174893

Additional Comments

That floor was last increased in October 2020 (#3501).

Some relevant CMake version dates:

Discovered while working on #5638 .

@jameslamb
Copy link
Collaborator Author

If you're finding this from a search engine... please consider contributing!

To resolve this, find the oldest CMake supported by LightGBM's current configuration. To do that, use something like the reproducible example in the original post to test versions one at a time.

Inspect the release notes for that version to identify what might have changed to make LightGBM incompatible with older versions.

If LightGBM's CMakeLists.txt can be modified to support and older version of CMake, make those modifications and repeat the process. Otherwise, increase the minimum version in CMakeLists.txt to that oldest supported version.

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

Successfully merging a pull request may close this issue.

1 participant