google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.17k stars 2.12k forks source link

cmake(MSVC): building ortools_full.lib is not working in Debug #3822

Open Mizux opened 1 year ago

Mizux commented 1 year ago

As spotted by user the cmake/bundle-install.cmake.in is not working in config Debug since we don't take into account the variable CMAKE_DEBUG_POSTFIX.

here we should add few wildcard (or better use ${CMAKE_DEBUG_POSTFIX}) to find the correct static lib dependencies https://github.com/google/or-tools/blob/a8346044239357a1e3dd4b321d38f2098c9ac14b/cmake/bundle-install.cmake.in#L16-L38

Todo:

ref: https://cmake.org/cmake/help/latest/variable/CMAKE_CONFIG_POSTFIX.html#variable:CMAKE_%3CCONFIG%3E_POSTFIX

Mizux commented 7 months ago

to test:

cmake -S. -Bbuild -DBUILD_DEPS=ON
cmake --build build --config Debug -v -j 8
cmake --install build --config Debug --prefix install

ref:

Mizux commented 7 months ago

Currently zlib and protobuf do use DEBUG_POSTFIX ref:

Mizux commented 7 months ago

Postponed to next release since even Debug build seems broken: trace:

 cmake --build build --config Debug -v -j 12
 ...
"C:\Users\...\or-tools\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\...\or-tools\build\ortools\math_opt\samples\cpp\cutting_stock.vcxproj" (default target) (173) ->
absl_synchronization.lib(mutex.obj) : error LNK2005: "private: void __cdecl absl::lts_20240116::Mutex::Dtor(void)" (?Dtor@Mutex@lts_20240116@absl@@AEAAXXZ) already defined in ortools.lib(model_storage.obj)
[C:\Users\...\or-tools\build\ortools\math_opt\samples\cpp\cutting_stock.vcxproj]
C:\Users\...\or-tools\build\DEBUG\bin\cutting_stock.exe : fatal error LNK1169: one or more multiply defined symbols found 
[C:\Users\...\or-tools\build\ortools\math_opt\samples\cpp\cutting_stock.vcxproj]

same for any executable -> need to dig for next release...

EddyXorb commented 6 months ago

Postponed to next release since even Debug build seems broken: trace:

 cmake --build build --config Debug -v -j 12
 ...
"C:\Users\...\or-tools\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\...\or-tools\build\ortools\math_opt\samples\cpp\cutting_stock.vcxproj" (default target) (173) ->
absl_synchronization.lib(mutex.obj) : error LNK2005: "private: void __cdecl absl::lts_20240116::Mutex::Dtor(void)" (?Dtor@Mutex@lts_20240116@absl@@AEAAXXZ) already defined in ortools.lib(model_storage.obj)
[C:\Users\...\or-tools\build\ortools\math_opt\samples\cpp\cutting_stock.vcxproj]
C:\Users\...\or-tools\build\DEBUG\bin\cutting_stock.exe : fatal error LNK1169: one or more multiply defined symbols found 
[C:\Users\...\or-tools\build\ortools\math_opt\samples\cpp\cutting_stock.vcxproj]

same for any executable -> need to dig for next release...

I confirm that. It happens exactly to me using vs 2022 and only on debug build.

I think it has to do with a recent change in abseils Mutex::Dtor. There is a condition that inlines the Mutex::Dtor when NDEBUG is defined for performance reasons, and defines it in mutex.cc otherwise with a debug logging machinery in this Dtor, which was formerly (202308) the default in every case: https://github.com/abseil/abseil-cpp/commit/f3760b4d3b2773d1cb8e9ddda29dc9bce386d540

A simple solution would be to patch this part back to the abseil 202308-state, or wait for the already open issue to be resolved for the next release of abseil, see:

This error however makes me think that the reason may as well be in how ortools' cmake is configured. Maybe DEBUG is not always set for every target or the BUILD_ABSEIL_DLL is not correctly set, I did not check it so far.

Regarding the original issue of bundle install not working on windows: I confirm that it does not work be it on Debug or Release. The execute command fails in both configs, saying it does not find libortools_all.lib (during removal call at top of bundle-install.cmake).