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

[CMake] Use CMAKE_MSVC_RUNTIME_LIBRARY to apply /MT #6484

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hcho3
Copy link
Contributor

@hcho3 hcho3 commented Jun 14, 2024

Use the built-in flag CMAKE_MSVC_RUNTIME_LIBRARY in CMake to robustly handle the linking mode for the Windows C runtime (/MD vs /MT). See https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html

CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Looks good to me! Just left one small request to move this code back down inside the if(BUILD_CPP_TEST) block.

Don't worry about the failing CI jobs... they're flaky and the failures are unrelated to your changes.

CMakeLists.txt Outdated Show resolved Hide resolved
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
# Use /MT flag to statically link the C runtime
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hcho3 could you please look into https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=16422&view=logs&j=1f4df553-f999-5fff-c6fe-71123c872ae2&t=3537c7a9-e1e2-54d5-18f4-f7d9e02b9f6d?

boosting.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in test_array_args.obj [D:\a\1\s\build\testlightgbm.vcxproj]

Does this maybe need to be set earlier, before the target is declared, to affect the flags? I'm not really sure.

Copy link
Contributor Author

@hcho3 hcho3 Jun 20, 2024

Choose a reason for hiding this comment

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

Yes, I think this has to be set before targets are created.

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

Successfully merging this pull request may close these issues.

None yet

2 participants