UCL / STIR

Software for Tomographic Image Reconstruction
http://stir.sourceforge.net/
Other
112 stars 94 forks source link

OpenMP linking errors on Windows using Ninja and clang #1129

Open KrisThielemans opened 1 year ago

KrisThielemans commented 1 year ago

1127 attempts to use Ninja on Appveyor (among trying to use sccache). It fails due to (unrelated) linking errors with OpenMP. Apparently the linker doesn't get passed the correct flag. This is likely caused by switching to Ninja, which I had to do as the VS Generator ignores the *COMPILER_LAUNCHER (I guess I could try nmake). But this is using the clang compiler as opposed to cl. so lots of things change.

errors like

lld-link: error: undefined symbol: __kmpc_dispatch_init_8
>>> referenced by iterative_KOSMAPOSL.lib(KOSMAPOSLReconstruction.cxx.obj):(.omp_outlined.)
>>> referenced by iterative_KOSMAPOSL.lib(KOSMAPOSLReconstruction.cxx.obj):(.omp_outlined..1)

and

lld-link: error: undefined symbol: omp_get_num_threads
>>> referenced by recon_buildblock.lib(PoissonLogLikelihoodWithLinearModelForMeanAndProjData.cxx.obj):(.omp_outlined.)
>>> referenced by recon_buildblock.lib(PoissonLogLikelihoodWithLinearModelForMeanAndProjData.cxx.obj):(.omp_outlined..1)

I don't think this is our problem, but CMake's FindOpenMP.

Originally posted by @KrisThielemans in https://github.com/UCL/STIR/issues/1127#issuecomment-1374934263

KrisThielemans commented 1 year ago

https://github.com/UCL/STIR/pull/1127/commits/8eaa7dccafd1cb9999875d2339bd40e4166a54cc removed any trace of sccache from the build, just to check.

https://ci.appveyor.com/project/KrisThielemans/stir/builds/45873849#L31028 shows that no openmp flag nor library is added for linking. Cutting some stuff it reads

C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Wno-undefined-var-template -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt   src/utilities/CMakeFiles/list_detector_and_bin_info.dir/list_detector_and_bin_info.cxx.obj <cut> 
 src/buildblock/buildblock.lib  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames"

other bits from the log

cmake.exe .. -G Ninja -DCMAKE_INSTALL_PREFIX=%CMAKE_INSTALL_PREFIX% -DCMAKE_BUILD_TYPE=%CONFIGURATION%  -DCMAKE_CONFIGURATION_TYPES=%CONFIGURATION% -DSTIR_OPENMP=ON
[00:00:11] -- The C compiler identification is Clang 9.0.1 with GNU-like command-line
[00:00:12] -- The CXX compiler identification is Clang 9.0.1 with GNU-like command-line
...
[00:00:16] -- Found OpenMP_C: -fopenmp=libomp (found version "3.1") 
[00:00:16] -- Found OpenMP_CXX: -fopenmp=libomp (found version "3.1") 
[00:00:16] -- Found OpenMP: TRUE (found version "3.1") 
...
[00:00:21] cmake.exe --build . --config %CONFIGURATION%

Relevant CMake lines https://github.com/UCL/STIR/blob/f75bd042560debd000a61508b9e940d751b3dafa/src/CMakeLists.txt#L158 https://github.com/UCL/STIR/blob/f027d10d335881ec0ff7a6a34ec28f72ca72763c/src/buildblock/CMakeLists.txt#L145 https://github.com/UCL/STIR/blob/f75bd042560debd000a61508b9e940d751b3dafa/src/recon_buildblock/CMakeLists.txt#L133

KrisThielemans commented 1 year ago

Appveyor for VS 2015 is running with cmake version 3.16.2, that'll explain a lot as CLang support has improved in CMake. I guess best to try with VS 2019 or 2022 where it will use 3.24.2.

https://www.appveyor.com/docs/windows-images-software/

KrisThielemans commented 1 year ago

This still occurs with cmake version 3.24.2 and Clang 14.0.6 (on AppVeyor with the VS 2022 VM, so therefore Ninja 1.11.1). Build is https://ci.appveyor.com/project/KrisThielemans/stir/builds/45938757. Log file copied here. log.txt

KrisThielemans commented 1 year ago

I've created https://discourse.cmake.org/t/openmp-linking-errors-on-windows-using-ninja-and-clang/7246