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

Change cxx standard from 11 to 14 in CMake #6429

Closed
wants to merge 1 commit into from
Closed

Change cxx standard from 11 to 14 in CMake #6429

wants to merge 1 commit into from

Conversation

donaldkuck
Copy link

compile in macos with clang15 failed when cxx11 in cmake because enable_if_t is available since c++14

@jameslamb
Copy link
Collaborator

jameslamb commented Apr 26, 2024

Thanks for using LightGBM.

We are going to need a lot more information than this before accepting this patch to change the default C++ standard for the entire project.

  • what operating system?
  • how are you building and installing LightGBM (specific commands)?
  • how are you building and installing clang (specific commands)?
  • can you share the logs from the build and the exact error(s) you encountered?

LightGBM is built with multiple different versions of clang (including 16, 17, and 18) across two different versions of Ubuntu, and for multiple configurations of LightGBM build options. It's also tested on multiple versions of macOS and AppleClang.

See #6178 (comment)

Almost all of those leave the project's C++ standard at its default, C++11.

The issue you're experiencing cannot simply be "LightGBM can't be compiled with clang15".

@donaldkuck
Copy link
Author

donaldkuck commented Apr 28, 2024

@jameslamb Hi, my environment info:
os:
macOS 14.3
clang:
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.3.0
Thread model: posix

when I compile with no modifications, there are some errors:

mkdir build
cd build && cmake ..
make -j8
# errors:
LightGBM/external_libs/eigen/Eigen/src/Core/util/Meta.h:310:22: error: no template named 'enable_if_t' in namespace 'std'; did you mean 'fmt::enable_if_t'?
struct array_size<T, std::enable_if_t<((T::SizeAtCompileTime & 0) == 0)>> {
                     ^~~~~~~~~~~~~~~~
                     fmt::enable_if_t

In https://en.cppreference.com/w/cpp/types/enable_if, it saided that enable_if_t is since c++14:

Helper types

template< bool B, class T = void >using enable_if_t = typename enable_if::type; |   | (since C++14)

@jameslamb
Copy link
Collaborator

jameslamb commented Apr 28, 2024

Thanks for the details. I'm not able to replicate that.

I just compiled the latest version of LightGBM on an M2 macOS laptop (very similar to your setup).

git clone \
    --recursive \
    https://github.com/microsoft/LightGBM.git \
    /tmp/LightGBM

cd /tmp/LightGBM
cmake -B build -S .
cmake --build build

Compilation of LightGBM succeeded, using a very similar version of AppleClang to the one you're using.

configure logs (click me)
-- The C compiler identification is AppleClang 15.0.0.15000309
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) 
-- Found OpenMP_C: -Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include (found version "5.0") 
-- Found OpenMP_CXX: -Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include (found version "5.0") 
-- Found OpenMP: TRUE (found version "5.0")  
-- Performing Test MM_PREFETCH
-- Performing Test MM_PREFETCH - Failed
-- Performing Test MM_MALLOC
-- Performing Test MM_MALLOC - Success
-- Using _mm_malloc
-- Configuring done (0.9s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/LightGBM/build
Build logs (click me)
[  2%] Building CXX object CMakeFiles/lightgbm_capi_objs.dir/src/c_api.cpp.o
[ 10%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/config_auto.cpp.o
[ 10%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/bin.cpp.o
[ 10%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/config.cpp.o
[ 12%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/dataset.cpp.o
[ 15%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/dataset_loader.cpp.o
[ 17%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/file_io.cpp.o
[ 20%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/json11.cpp.o
[ 23%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/metadata.cpp.o
[ 23%] Built target lightgbm_capi_objs
[ 25%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/parser.cpp.o
[ 28%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/train_share_states.cpp.o
[ 30%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/tree.cpp.o
[ 33%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/metric/dcg_calculator.cpp.o
[ 35%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/metric/metric.cpp.o
[ 38%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linker_topo.cpp.o
[ 41%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linkers_mpi.cpp.o
[ 43%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linkers_socket.cpp.o
[ 46%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/network.cpp.o
[ 48%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/objective/objective_function.cpp.o
[ 51%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/data_parallel_tree_learner.cpp.o
[ 53%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/feature_histogram.cpp.o
[ 56%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/feature_parallel_tree_learner.cpp.o
[ 58%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/gpu_tree_learner.cpp.o
[ 61%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/gradient_discretizer.cpp.o
[ 64%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/linear_tree_learner.cpp.o
[ 66%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/serial_tree_learner.cpp.o
[ 69%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/tree_learner.cpp.o
[ 71%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/voting_parallel_tree_learner.cpp.o
[ 74%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/utils/openmp_wrapper.cpp.o
[ 89%] Built target lightgbm_objs
[ 94%] Linking CXX shared library /tmp/LightGBM/lib_lightgbm.dylib
[ 94%] Building CXX object CMakeFiles/lightgbm.dir/src/main.cpp.o
[ 97%] Building CXX object CMakeFiles/lightgbm.dir/src/application/application.cpp.o
[ 97%] Built target _lightgbm
[100%] Linking CXX executable /tmp/LightGBM/lightgbm
[100%] Built target lightgbm

More information about my setup:

cmake --version
# cmake version 3.26.4

clang++ --version
# Apple clang version 15.0.0 (clang-1500.3.9.4)
# Target: arm64-apple-darwin23.4.0
# Thread model: posix
# InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I do not see any uses of enable_if_t in LightGBM.

git grep enable_if_t

I strongly suspect that the issue you're facing lies in some difference between your setup and mine. If you want to see LightGBM drop C++11 support by default, we'll have to identify that difference.

So, to start... what do you observe if you run the exact same commands I shared above? Please share all the logs as I did.

@donaldkuck
Copy link
Author

@jameslamb Hi, I find that I use wrong submodule version:

git submodule update --init --remote

Sorry for my mistake. I will close the PR.

@donaldkuck donaldkuck closed this Apr 28, 2024
@jameslamb
Copy link
Collaborator

ah interesting! Ok then yeah I guess maybe you got a different version of Eigen than this project uses.

No problem, thanks for using LightGBM.

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

Successfully merging this pull request may close these issues.

3 participants