CUDA C++ problems with CMake on CLion IDE - c++

I'm trying to start a project with CUDA C++ using CLion as an IDE.
I installed a fresh version of CUDA Developer Tools (v10.2) and tried to load the changes of the MakeFile.
Apparently, the CUDA compiler (nvcc) doesn't get properly linked, but I'm not sure this is the problem.
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(test_cuda LANGUAGES CXX CUDA)
find_package(CUDA)
set(CMAKE_CXX_STANDARD 17)
add_executable(test_cuda main.cu)
The result I get is the following:
"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" <path_to_project>\test_cuda
-- The CUDA compiler identification is NVIDIA 10.2.89
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe -- broken
CMake Error at E:/Program Files/JetBrains/CLion 2019.2.5/bin/cmake/win/share/cmake-3.15/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: <path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_5cf15\fast && "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_5cf15.dir\build.make /nologo -L CMakeFiles\cmTC_5cf15.dir\build
Building CUDA object CMakeFiles/cmTC_5cf15.dir/main.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v10.2\bin\nvcc.exe -D_WINDOWS -Xcompiler=" /GR /EHsc" -Xcompiler="-Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -x cu -c <path_to_project>\test_cuda\cmake-build-debug-visual-studio\CMakeFiles\CMakeTmp\main.cu -o CMakeFiles\cmTC_5cf15.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_5cf15.dir\,-FS
main.cu
Linking CUDA executable cmTC_5cf15.exe
"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_5cf15.dir --rc=C:\PROGRA~2\WI3CF2~1\8.1\bin\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\8.1\bin\x86\mt.exe --manifests -- C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo "CMakeFiles\cmTC_5cf15.dir\main.cu.obj" #<path_to_appdata>\Local\Temp\nm8647.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo CMakeFiles\cmTC_5cf15.dir\main.cu.obj /out:cmTC_5cf15.exe /implib:cmTC_5cf15.lib /pdb:<path_to_project>\test_cuda\cmake-build-debug-visual-studio\CMakeFiles\CMakeTmp\cmTC_5cf15.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 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64 cudadevrt.lib cudart_static.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_5cf15.dir/intermediate.manifest CMakeFiles\cmTC_5cf15.dir/manifest.res" failed (exit code 1112) with the following output:
CMakeFiles\cmTC_5cf15.dir\main.cu.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
NMAKE : fatal error U1077: '"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
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 "<path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeOutput.log".
See also "<path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeError.log".
[Finished]
Where I substitute the path to the project folder with <path_to_project>.
The .cu file is just a simple hello world source file for now, since I'm trying to solve the issue with the CUDA compiler first.
I can't really find any way to solve this.
Thank you a lot in advance.

The message module machine type 'x64' conflicts with target machine type 'X86' is the crux of the problem. This indicates you have a 32-bit vs 64-bit architecture mismatch. Please be sure you use consistent project and compiler settings.
So, if you are compiling for a 64-bit architecture, make sure your project (CMake) settings are configured to build x64 targets. Also, you must be sure to use the 64-bit versions of the compilation tools (nvcc). Specifically for your case, your linker flags appear to contain /machine:X86, which would need to be removed if you are aiming for a 64-bit build. This can likely be configured through the CLion IDE in your Toolchain settings.

Related

The C compiler is not able to generate a single test (C++ IntelliSense information may be out of date, generate the CMake cache to refresh.)

the name might be long but that's all I can think of to describe the issue. I was trying to follow a pybind11 tutorial and when I cloned all the examples my intellisense started acting up, first on VSCode with it not fiding the indlude folder (despite adding the path to the "C/C++ configuration") and then on Visual Studio 2022 with Cmake throwing an error when I tried to fix "C++ IntelliSense information may be out of date, generate the CMake cache to refresh".
The error is as follows :
`
Severity Code Description Project File Line Suppression State
Error CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/jackd/Desktop/exemple_pybind/out/build/x64-Debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_e044f && [1/2] Building C object CMakeFiles\cmTC_e044f.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_e044f.exe
FAILED: cmTC_e044f.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_e044f.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_e044f.dir\testCCompiler.c.obj /out:cmTC_e044f.exe /implib:cmTC_e044f.lib /pdb:cmTC_e044f.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_e044f.dir/manifest.res CMakeFiles\cmTC_e044f.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. C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake 69
`
and since I'm no c++ pro I couldn't figure what this meant.
(I tried the other related topics: here and here)

Configure CMake in windows to use clang from command line to get modern OpenMP support

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, then cmake .. (from the newly created folder) and finally cmake --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, then cmake .. -T "Intel C++ Compiler 19.0" (from the newly created folder) and finally cmake --build . --config Release. This supports OpenMP 5.0 but its licenses are pretty expensive for me.
MinGW x64 g++: mkdir build-g++, then cmake .. -G "MinGW Makefiles" (from the newly created folder) and finally cmake --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, then cmake -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, then cmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl .. (from the newly created folder and changing the PATH 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
I was able to duplicate this error for the Clang+MSVC case. Because we are attempting to use the Visual-Studio-tailored compiler from outside Visual Studio (i.e. the command line), it is necessary to initialize the VS build environment in our command line before using the compiler. The VCVarsXX.bat files accomplish this; they are part of the VS Command Prompt tools. So by picking your architecture (x86, x64, etc) and running the script, this should allow CMake to build the simple test program with clang-cl and proceed. Here is where it is located for VS 2019:
>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
>cmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl ..
-- The CXX compiler identification is Clang 8.0.1
-- 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 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
...
To expand on the OpenMP issue, I personally found using find_package(OpenMP REQUIRED) to be pretty fruitless. As you mentioned, I also received this CMake error:
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
There are a few suggestions on this site (for example here and here) claiming that populating all of the variables manually allows FindOpenMP.cmake to successfully find the libraries. I tried this with your example CMake file, with some success:
cmake_minimum_required (VERSION 2.8)
project(test_openmp LANGUAGES CXX)
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(OpenMP_CXX_LIB_NAMES "libomp" "libiomp5")
set(OpenMP_libomp_LIBRARY libomp)
set(OpenMP_libiomp5_LIBRARY libiomp5)
#OPENMP
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
# Library
add_library(example_lib SHARED example_lib.h example_lib.cpp)
target_link_libraries(example_lib PUBLIC ${OpenMP_CXX_LIBRARIES})
target_compile_definitions(example_lib PRIVATE EXEMPLE_LIB_EXPORT)
# Executable
add_executable(test_openmp test_openmp.cpp)
target_link_libraries(test_openmp example_lib)
This succeeded in "finding" the libraries on the second CMake configuration attempt (the first always yielded the same Could NOT find OpenMP_CXX error as before):
>cmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl ..
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "3.1")
-- Found OpenMP: TRUE (found version "3.1")
-- Configuring done
-- Generating done
However, this failed to build the executable, as none of the CMake OpenMP variables (particularly OpenMP_CXX_LIBRARIES) actually point to the library location. The shortcomings of CMake's FindOpenMP.cmake have been raised on the CMake issue site here, and there appear to be relevant limitations on the LLVM/Clang end as well.
Regardless, the cleanest way I was able to get the example working was to ditch find_package() altogether. The following allowed me to successfully generate the buildsystem, and compile and run the executable:
cmake_minimum_required (VERSION 2.8)
project(test_openmp LANGUAGES CXX)
set(OpenMP_LIBRARY_DIR "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/lib")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# Tell CMake where to find the OpenMP libraries.
link_directories(${OpenMP_LIBRARY_DIR})
# Library
add_library(example_lib SHARED example_lib.h example_lib.cpp)
# Link in the OpenMP libraries.
target_link_libraries(example_lib PUBLIC libomp libiomp5md)
target_compile_definitions(example_lib PRIVATE EXEMPLE_LIB_EXPORT)
# Executable
add_executable(test_openmp test_openmp.cpp)
target_link_libraries(test_openmp example_lib)

Visual Studio can't detect my Clang compiler installation

I'm using the latest VS 2019 16.2, which is supposed to have Clang with MSBuild support as well Clang w/ CMake of course.
I installed the CMake components as well as the Clang-cl for v142 build tools (But not the Clang Compiler component that comes with VS!) because I already have Clang compiler v8.0.0 installed in the default path in my system.
I want to use Clang (either through MSBuild or CMake) but both approaches failed.
VS simply doesn't seem to detect my compiler (although the version is supported, supposedly).
Is there a way I can manually make it detect it? May add a path in some options or reinstall clang?
I don't want to install the VS one for my specific reasons.
Severity Code Description Project File Line Suppression State
Error CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"c:/program files (x86)/microsoft visual studio/2019/community/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/HP/Source/Repos/CMakeProject1/out/build/x64-Clang-Debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_8f083
[1/2] Building C object CMakeFiles\cmTC_8f083.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_8f083.exe
FAILED: cmTC_8f083.exe
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_8f083.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1422~1.279\bin\Hostx86\x86\link.exe /nologo CMakeFiles\cmTC_8f083.dir\testCCompiler.c.obj /out:cmTC_8f083.exe /implib:cmTC_8f083.lib /pdb:cmTC_8f083.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 /foCMakeFiles\cmTC_8f083.dir/manifest.res CMakeFiles\cmTC_8f083.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. C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake 60

Cannot link to Boost library with MSVC: Cannot open file *.lib

I'm using CLion and CMake to link with Boost and as toolchain I chose the MSVC compiler:
My architecture is configured as amd64 since I'm running a 64-bit system (the default of x86 only tries to find the 32-bit versions of Boost which I don't want).
Furthermore I compiled the 64-bit libraries using this guide. I setup my CMake file respectively:
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
set(BOOST_LIBRARYDIR "C:/local/boost_1_69_0_b1_rc3/stage/x64/lib")
set(BOOST_INCLUDEDIR "C:/local/boost_1_69_0_b1_rc3/boost")
My main.cpp compiles just fine but I'm getting a linker error:
====================[ Build | BoostTesting | Debug ]============================
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe --build D:\Cpp\BoostTesting\cmake-build-debug --target BoostTesting --
[ 50%] Linking CXX executable BoostTesting.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~3\2017\ENTERP~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\BoostTesting.dir\objects1.rsp /out:BoostTesting.exe /implib:BoostTesting.lib /pdb:D:\Cpp\BoostTesting\cmake-build-debug\BoostTesting.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_filesystem-vc141-mt-gd-x64-1_69.lib C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_system-vc141-mt-x64-1_69.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\BoostTesting.dir/intermediate.manifest CMakeFiles\BoostTesting.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_iostreams-vc141-mt-gd-x64-1_69.lib'
NMAKE : fatal error U1077: 'C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
When using x86_amd64 as architecture it also fails to link. The other architectures don't make sense for my PC:
Using the pre-compiled binaries from here also fails to link. How to fix this linking problem?
Just setting BOOST_ROOT in CMakeLists.txt
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
and using amd64 as the architecture surprisingly did the trick now. Using MSVC with CMake is better supported with Visual Studio (quite obviously) and linking to Boost was no issue anymore. Now the build also works from CLion but Visual Studio should be preferred until CLion maybe gets better MSVC integration.

clang++ in CLion Windows, how to run with MinGW--w64 instead of Windows VC?

What I have
Windows 10 x64
MinGW-w64 toolchain 7.3.0, 32+64, 64bit version set in PATH
CLang Windows distribution 6.0.0, 32+64, 64bit version set in PATH
CLion 2018.1 & built-in cmake
Set CMake preference inside CLion following this post
Will not installed VS or VS build tools.
Can compile cpp files from command line with both g++ and clang++ without error. For clang++ I have to set flag -target x86_64-pc-mingw64 due to lack of VC toolchain and headers.
What I want
Set a functional CMake profile using clang++ compiler.
I have set a CMake profile according to the link above. However, clion give error
The Clang compiler tool
"C:/Program Files/LLVM/bin/clang.exe"
targets the MSVC ABI but has a GNU-like command-line interface. This is
not supported. Use 'clang-cl' instead, e.g. by setting 'CC=clang-cl' in
the environment. Furthermore, use the MSVC command-line environment.
If I set C and CXX COMPILERs to clang-cl instead of setting TOOLCHAIN PREFIX to LLVM, there will be an error.
CMake Error at C:/Program Files/JetBrains/CLion
2018.1/bin/cmake/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52
(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/huang/Documents/Programs/grade/cmake-build-release-
clang-1/CMakeFiles/CMakeTmp
Run Build Command:"C:/mingw64/bin/mingw32-make.exe" "cmTC_181bf/fast"
C:/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_181bf.dir\build.make
CMakeFiles/cmTC_181bf.dir/build
mingw32-make.exe[1]: Entering directory
'C:/Users/huang/Documents/Programs/grade/cmake-build-release-clang-
1/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_181bf.dir/testCCompiler.c.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe /nologo /DWIN32 /D_WINDOWS /W3 /MDd
/Zi /Ob0 /Od /RTC1 /FoCMakeFiles\cmTC_181bf.dir\testCCompiler.c.obj
/FdCMakeFiles\cmTC_181bf.dir/ -c
C:\Users\huang\Documents\Programs\grade\cmake-build-release-clang-
1\CMakeFiles\CMakeTmp\testCCompiler.c
Linking C executable cmTC_181bf.exe
"C:\Program Files\JetBrains\CLion 2018.1\bin\cmake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_181bf.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2018.1\bin\cmake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_181bf.dir --manifests -- CMAKE_LINKER-NOTFOUND /nologo #CMakeFiles\cmTC_181bf.dir\objects1.rsp /out:cmTC_181bf.exe /implib:cmTC_181bf.lib /pdb:C:\Users\huang\Documents\Programs\grade\cmake-build-release-clang-1\CMakeFiles\CMakeTmp\cmTC_181bf.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
RC Pass 1: command "rc /foCMakeFiles\cmTC_181bf.dir/manifest.res CMakeFiles\cmTC_181bf.dir/manifest.rc" failed (exit code 0) with the following output:
缁崵绮洪幍鍙ョ瑝閸掔増瀵氱�规氨娈戦弬鍥︽閵嗕慷ingw32-make.exe[1]: *** [CMakeFiles\cmTC_181bf.dir\build.make:98: cmTC_181bf.exe] Error -1
mingw32-make.exe[1]: Leaving directory 'C:/Users/huang/Documents/Programs/grade/cmake-build-release-clang-1/CMakeFiles/CMakeTmp'
mingw32-make.exe: *** [Makefile:125: cmTC_181bf/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
I guess it may be because I haven't set the target as I will do in the command line, and the default target is VC. In CLion interface, how should I do it?
There is a combination of 2 problems:
CMake doesn't support the native clang++.exe driver (see the related ticket).
Even if it would, I don't think MinGW could work with the installed clang distribution. You'll have to install clang as a MinGW package (see e.g. this readme, here is the specific package).
For now there is no specific support for this use case in CLion itself (so it should work when everything is set up properly, but it doesn't offer any help to do it).