I have a small test project that uses OpenMP for parallelization. My target is to compile it so it produces .dll
and .lib
for libraries (because my real project links to external libraries distributed using these types), with support for OpenMP 4.5 or newer and do it from the command line so it can be done on a docker for testing and checking (the docker part is out of the scope of this question, it is just for reference on why I need it to work from the command line). I can compile this project with different compilers with which I am not happy:
- MSVC:
mkdir build-msvc
, thencmake ..
(from the newly created folder) and finallycmake --build . --config Release
. This compiles fine but only supports OpenMP 2.0, therefore is not a good option for my real project. - Intel Parallel Studio:
mkdir build-intel
, thencmake .. -T "Intel C++ Compiler 19.0"
(from the newly created folder) and finallycmake --build . --config Release
. This supports OpenMP 5.0 but its licenses are pretty expensive for me. - MinGW x64 g++:
mkdir build-g++
, thencmake .. -G "MinGW Makefiles"
(from the newly created folder) and finallycmake --build .
. It supports OpenMP 4.5 but this compiler is not compatible wiht.lib
(as far as I know) which I already mentioned is necessary for me.
I have tried without success to use clang:
- CLANG from MSVC:
mkdir build-clang-msvc
, thencmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl ..
(from the newly created folder), but it fails with the following error:
-- The CXX compiler identification is Clang 8.0.1 with MSVC-like command-line -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe -- broken CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message): The C++ compiler "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: C:/Users/[USER NAME]/source/repos/test_openmp/build-clang-msvc/CMakeFiles/CMakeTmp Run Build Command(s):C:/PROGRA~2/MICROS~1/2019/COMMUN~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe cmTC_bd131 && [1/2] Building CXX object CMakeFiles\cmTC_bd131.dir\testCXXCompiler.cxx.obj [2/2] Linking CXX executable cmTC_bd131.exe FAILED: cmTC_bd131.exe cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_bd131.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\ld.exe /nologo CMakeFiles\cmTC_bd131.dir\testCXXCompiler.cxx.obj /out:cmTC_bd131.exe /implib:cmTC_bd131.lib /pdb:cmTC_bd131.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." RC Pass 1: command "rc /fo CMakeFiles\cmTC_bd131.dir/manifest.res CMakeFiles\cmTC_bd131.dir/manifest.rc" failed (exit code 0) with the following output: The system cannot find the file specified ninja: build stopped: subcommand failed. CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project) -- Configuring incomplete, errors occurred! See also "C:/Users/[USER NAME]/source/repos/test_openmp/build-clang-msvc/CMakeFiles/CMakeOutput.log". See also "C:/Users/[USER NAME]/source/repos/test_openmp/build-clang-msvc/CMakeFiles/CMakeError.log".
- Clang and Ninja apart from MSVC:
mkdir build-clang-ninja
, thencmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl ..
(from the newly created folder and changing thePATH
environmental variable so the non-msvc are found first), but it fails with the following error:
-- The CXX compiler identification is Clang 9.0.0 with MSVC-like command-line -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- broken CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message): The C++ compiler "C:/Program Files/LLVM/bin/clang-cl.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: C:/Users/[USER NAME]/source/repos/test_openmp/buid-clang-ninja/CMakeFiles/CMakeTmp Run Build Command(s):C:/Ninja/ninja.exe cmTC_50b73 && [1/2] Building CXX object CMakeFiles\cmTC_50b73.dir\testCXXCompiler.cxx.obj [2/2] Linking CXX executable cmTC_50b73.exe FAILED: cmTC_50b73.exe cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_50b73.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- CMAKE_LINKER-NOTFOUND /nologo CMakeFiles\cmTC_50b73.dir\testCXXCompiler.cxx.obj /out:cmTC_50b73.exe /implib:cmTC_50b73.lib /pdb:cmTC_50b73.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." RC Pass 1: command "rc /fo CMakeFiles\cmTC_50b73.dir/manifest.res CMakeFiles\cmTC_50b73.dir/manifest.rc" failed (exit code 0) with the following output: The system cannot find the file specified ninja: build stopped: subcommand failed. CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project) -- Configuring incomplete, errors occurred! See also "C:/Users/[USER NAME]/source/repos/test_openmp/buid-clang-ninja/CMakeFiles/CMakeOutput.log". See also "C:/Users/[USER NAME]/source/repos/test_openmp/buid-clang-ninja/CMakeFiles/CMakeError.log".
Any ideas on how to proceed with the clang? I think it is my best option for what I want to achieve (compile my test program with support for OpenMP 4.5 or newer and producing .lib
and .dll
).
Related posts/webpages that I have checked but have been non-useful to solve this:
- Building c++ project on Windows with CMake, Clang and Ninja
- Building with CMake, Ninja and Clang on Windows
- Ways to Compile with Clang on Windows, specifically setting the linker:
-DCMAKE_LINKER="C:/Program Files/LLVM/bin/lld-link.exe"
- CMake building for Windows (clang-cl) using Ninja Generator
- Clang-cl user manual
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
. I'll dig into this new error and if I don't find an answer I'll post a new question. Thank you! – apalomer