Setting CUDA_NVCC_FLAGS using CMake - c++

I am trying to compile a CUDA project using CMake on Windows. I am not familiar with make or CMake and I have done some reading over the past few days, but I am still not able to figure this out. I get the following error message:
Chri#Riemann-PC /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64
$ make
[ 1%] Built target lapacktest
[ 1%] Building NVCC (Device) object CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o
nvcc fatal : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions 2010, 2012, and 2013 are supported
CMake Error at magma_generated_zherk_batched_core.cu.o.cmake:207 (message):
Error generating
/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o
CMakeFiles/magma.dir/build.make:2058: recipe for target 'CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o' failed
make[2]: *** [CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o] Error 1
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/magma.dir/all' failed
make[1]: *** [CMakeFiles/magma.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Using the make VERBOSE=1 command, I get the following error:
cd /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas && /usr/bin/cmake.exe -D verbose:BOOL=1 -D build_configuration:STRING= -D generated_file:STRING=/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o -D generated_cubin_file:STRING=/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o.cubin.txt -P /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o.cmake
-- Removing /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o
/usr/bin/cmake.exe -E remove /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o
-- Generating dependency file: /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o.NVCC-depend
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/bin/nvcc.exe" -M -D__CUDACC__ /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/magmablas/zherk_batched_core.cu -o /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o.NVCC-depend -ccbin /usr/bin/gcc.exe -m64 -Xcompiler ,\"-fopenmp\",\"-Wall\",\"-Wno-unused-function\",\"-g\" -DHAVE_CUBLAS -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35 -DNVCC "-I/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/include" "-I/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/include" -I/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/include -I/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/control
nvcc fatal : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions 2010, 2012, and 2013 are supported
It is still using the gcc compiler (-ccbin /usr/bin/gcc.exe).
I went into the file: C:\Apps\ThirdParty\cygwin64\usr\share\cmake-3.3.2\Modules\FindCUDA.cmake and added the following lines:
set(VS_DIR "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin")
message(${VS_DIR})
set(CUDA_NVCC_FLAGS "-ccbin ${VS_DIR}" CACHE STRING "Semi-colon delimit multiple arguments.")
I also added the following line to the nvcc.profile file:
CUDA_NVCC_FLAGS += -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin";
Still no luck. I have spent a few days trying to fix this. I am grateful for any help in this matter.

The option to set the host compiler in FindCUDA is CUDA_HOST_COMPILER, see the FindCUDA documentation.
Try
set(CUDA_HOST_COMPILER "<path to compiler executable>")
or alternatively set it when invoking the cmake command
cmake .. -DCUDA_HOST_COMPILER=<path to compiler executable>
I guess the CUDA_HOST_COMPILER option overrides the ccbin settings of CUDA_NVCC_FLAGS. For other options you can use CUDA_NVCC_FLAGS in the way you tried. (Thus, the title is misleading. It is not a problem of how to set CUDA_NVCC_FLAGS.)
I use this often on Linux, however I don't have a Windows environment to test it there.

Related

ld.lld: error: could not open 'libLIBCMTD.a': No such file or directory

I recently installed vspkg and tried to build my c++ application with libcurl using command vcpkg.exe install curl:x64-windows-static
After i tried to compile it, i got an error on linking stage
ld.lld: error: could not open 'libLIBCMTD.a': No such file or directory
ld.lld: error: could not open 'libOLDNAMES.a': No such file or directory
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\testEnv.dir\build.make:140: C:/Users/Administrator/libtestEnv.dll] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/testEnv.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/testEnv.dir/rule] Error 2
mingw32-make: *** [Makefile:123: testEnv] Error 2
I also tried to install curl library non-static and everything went successfully but i want to have everything linked as one libary so it's not a good solution
My CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(testEnv)
# remove names of functions and optimize
set(CMAKE_CXX_FLAGS "-nolibc -s -O3 -Os -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fuse-ld=lld")
set(CMAKE_CXX_STANDARD 17)
find_package(CURL CONFIG REQUIRED)
add_library(testEnv SHARED main.cpp)
target_link_libraries(testEnv CURL::libcurl)
#collect all needed libraries to run
target_link_libraries(testEnv -static)
Any ideas how to fix that problem with linking? Maybe there is any solutions which would allow to exclude those problematic libs?
mingw32-make
looks like you are using mingw. Consider using the correct vcpkg triplet, e.g. x64-mingw-static.cmake.
x64-windows-static will use an installed VS toolchain.
Be aware that you also need to set -DVCPKG_TARGET_TRIPLET=x64-mingw-static and -DVCPKG_HOST_TRIPLET=x64-mingw-static in your cmake call. Also make sure cmake does clean configure.

Building TBB on Windows using MingW & Cmake

Hey I'm trying to build TBB on my Windows computer using MinGW & CMake. (gcc,,g++, ..)
I have already tried using the premade binaries but I keep getting undefined reference issues.
My cmake for the project I'm trying to import it in looks as following:
find_package(TBB REQUIRED tbb)
target_link_libraries(projectName PRIVATE ${TBB_IMPORTED_TARGETS})
I use the source code of https://github.com/oneapi-src/oneTBB/releases/tag/v2021.3.0 (latest)
and I make a build dir and cd into it and execute:
cmake .. -G "MinGW Makefiles"
followed by:
cmake --build .
also tried:
mingw32-make
Both result into
[ 1%] Building CXX object src/tbb/CMakeFiles/tbb.dir/address_waiter.cpp.obj
In file included from c:\users\refactor\downloads\onetbb-2021.3.0\onetbb-2021.3.0\include\oneapi\tbb\detail\_utils.h:26,
from C:\Users\Refactor\Downloads\oneTBB-2021.3.0\oneTBB-2021.3.0\src\tbb\address_waiter.cpp:17:
c:\users\refactor\downloads\onetbb-2021.3.0\onetbb-2021.3.0\include\oneapi\tbb\detail\_machine.h:67: error: ignoring '#pragma intrinsic ' [-Werror=unknown-pragmas]
67 | #pragma intrinsic(_mm_mfence)
|
compilation terminated due to -Wfatal-errors.
cc1plus.exe: all warnings being treated as errors
mingw32-make[2]: *** [src\tbb\CMakeFiles\tbb.dir\build.make:76: src/tbb/CMakeFiles/tbb.dir/address_waiter.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:454: src/tbb/CMakeFiles/tbb.dir/all] Error 2
mingw32-make: *** [makefile:165: all] Error 2```
As mentioned in the comments there are issues building with MinGW with the latest versions of TBB.
The last version of TBB I was able to build was 2020.0 using this command (replace intel64 with ia32 for 32-bit):
mingw32-make compiler=gcc arch=intel64 runtime=mingw tbb tbbmalloc CPLUS="g++ -static-libstdc++ -static-libgcc"

CMake is Unable to Compile a Simple Test Program in CLion [duplicate]

I am trying to get NVIDIA's CUDA setup and installed on my PC which has an NVIDIA GEFORCE RTX 2080 SUPER graphics card. After hours of trying different things and lots of research I have gotten CUDA to work using the Command Prompt, though trying to use CUDA in CLion will not work.
Using
nvcc main.cu -o build.exe
From the command line generates the executable and I can run it on the GPU, however I have the following error when trying to use CLion:
I believe this is the relevant part, however there is more if that is required
-- The CUDA compiler identification is unknown
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe -- broken
CMake Error at C:/Users/penci/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/201.7846.88/bin/cmake/win/share/cmake-3.16/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA PLEASE/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_03473\fast && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x86\nmake.exe" -f CMakeFiles\cmTC_03473.dir\build.make /nologo -L CMakeFiles\cmTC_03473.dir\build
Building CUDA object CMakeFiles/cmTC_03473.dir/main.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v11.0\bin\nvcc.exe -x cu -c "C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA PLEASE\cmake-build-debug\CMakeFiles\CMakeTmp\main.cu" -o CMakeFiles\cmTC_03473.dir\main.cu.obj
Thanks for any help!
============================== EDIT 1 =============================
Here is the full output from CLion (It is using a different project too but it is still the exact same output)
C:\Users\penci\AppData\Local\JetBrains\CLion2020.1\cygwin_cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST
-- The CUDA compiler identification is NVIDIA 11.0.194
-- Check for working CUDA compiler: /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe
-- Check for working CUDA compiler: /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe -- broken
CMake Error at /cygdrive/c/Users/penci/AppData/Local/JetBrains/CLion2020.1/cygwin_cmake/share/cmake-3.16.5/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make.exe cmTC_03d85/fast && /usr/bin/make -f CMakeFiles/cmTC_03d85.dir/build.make CMakeFiles/cmTC_03d85.dir/build
make[1]: Entering directory '/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp'
Building CUDA object CMakeFiles/cmTC_03d85.dir/main.cu.o
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe" -x cu -c /cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_03d85.dir/main.cu.o
c1xx: fatal error C1083: Cannot open source file: 'C:/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp/main.cu': No such file or directory
main.cu
make[1]: *** [CMakeFiles/cmTC_03d85.dir/build.make:66: CMakeFiles/cmTC_03d85.dir/main.cu.o] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_03d85/fast] Error 2
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 "/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
=============================== EDIT 2 ===============================
After switching to MSVC 2017 and Visual Studio toolchain I now get a slightly different error:
C:\Users\penci\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.7846.88\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA_TEST
-- The CUDA compiler identification is NVIDIA 11.0.194
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe -- broken
CMake Error at C:/Users/penci/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/201.7846.88/bin/cmake/win/share/cmake-3.16/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_23e94\fast && "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe" -f CMakeFiles\cmTC_23e94.dir\build.make /nologo -L CMakeFiles\cmTC_23e94.dir\build
Building CUDA object CMakeFiles/cmTC_23e94.dir/main.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v11.0\bin\nvcc.exe -D_WINDOWS -Xcompiler=" /GR /EHsc" -Xcompiler="-Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -x cu -c C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA_TEST\cmake-build-debug\CMakeFiles\CMakeTmp\main.cu -o CMakeFiles\cmTC_23e94.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_23e94.dir\,-FS
main.cu
Linking CUDA executable cmTC_23e94.exe
C:\Users\penci\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.7846.88\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_23e94.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo "CMakeFiles\cmTC_23e94.dir\main.cu.obj" #C:\Users\penci\AppData\Local\Temp\nmD0E.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_23e94.dir\main.cu.obj /out:cmTC_23e94.exe /implib:cmTC_23e94.lib /pdb:C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA_TEST\cmake-build-debug\CMakeFiles\CMakeTmp\cmTC_23e94.pdb /version:0.0 /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/v11.0/lib/x64 cudadevrt.lib cudart_static.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_23e94.dir/intermediate.manifest CMakeFiles\cmTC_23e94.dir/manifest.res" failed (exit code 1120) with the following output:
Creating library cmTC_23e94.lib and object cmTC_23e94.exp
MSVCRTD.lib(utility_app.obj) : error LNK2019: unresolved external symbol __imp_RoInitialize referenced in function __scrt_initialize_winrt
cmTC_23e94.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'C:\Users\penci\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.7846.88\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\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 "C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
I was able to get a simple "Hello World" compiling in CLion by making sure your PATH is updated to include
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin
My CMakeLists.txt looks like this
cmake_minimum_required(VERSION 3.17)
project(cuda_test CUDA)
find_package(CUDA)
set(CMAKE_CUDA_STANDARD 14)
add_executable(cuda_test main.cu)
set_target_properties(
cuda_test
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
And using Visual Studio 2017 with these settings in the toolchain

Building a simple C++ project on Windows, using CMake and clang

I'm trying to get a simple 'Hello World' program to build on Windows 10, preferably using CMake and clang. I can successfully compile, link and run the same project if I use the g++ compiler from MinGW, but have problems when I try using clang++.
I have CMake, MinGW and LLVM already installed and accessible in my path:
clang++
clang++: error: no input files
cmake --version
cmake version 3.16.0-rc1
I have set up environment variables for CMake to use clang:
echo %CC%
C:\Program Files\LLVM\bin\clang.exe
echo %CXX%
C:\Program Files\LLVM\bin\clang++.exe
Now when I run cmake with my simple "Hello World" C++ project, cmake complains about not being able to use clang:
cmake -G "MinGW Makefiles" ..
-- The CXX compiler identification is Clang 9.0.0 with GNU-like command-line
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler
"C:/Program Files/LLVM/bin/clang++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/pball/git/bchest/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe cmTC_838da/fast && C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_838da.dir\build.make CMakeFiles/cmTC_838da.dir/build
mingw32-make.exe[1]: Entering directory 'C:/Users/pball/git/bchest/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_838da.dir/testCXXCompiler.cxx.obj
C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -o CMakeFiles\cmTC_838da.dir\testCXXCompiler.cxx.obj -c C:\Users\pball\git\bchest\build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx
Linking CXX executable cmTC_838da.exe
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_838da.dir\link.txt --verbose=1
C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd #CMakeFiles\cmTC_838da.dir\objects1.rsp -o cmTC_838da.exe -Xlinker /implib:cmTC_838da.lib -Xlinker /pdb:C:\Users\pball\git\bchest\build\CMakeFiles\CMakeTmp\cmTC_838da.pdb -Xlinker /version:0.0 #CMakeFiles\cmTC_838da.dir\linklibs.rsp
lld-link: error: could not open 'kernel32.lib': no such file or directory
lld-link: error: could not open 'user32.lib': no such file or directory
lld-link: error: could not open 'gdi32.lib': no such file or directory
lld-link: error: could not open 'winspool.lib': no such file or directory
lld-link: error: could not open 'shell32.lib': no such file or directory
lld-link: error: could not open 'ole32.lib': no such file or directory
lld-link: error: could not open 'oleaut32.lib': no such file or directory
lld-link: error: could not open 'uuid.lib': no such file or directory
lld-link: error: could not open 'comdlg32.lib': no such file or directory
lld-link: error: could not open 'advapi32.lib': no such file or directory
lld-link: error: could not open 'oldnames.lib': no such file or directory
lld-link: error: could not open 'msvcrtd.lib': no such file or directory
CLANG_~1: error: linker command failed with exit code 1 (use -v to see invocation)
mingw32-make.exe[1]: *** [CMakeFiles\cmTC_838da.dir\build.make:88: cmTC_838da.exe] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/pball/git/bchest/build/CMakeFiles/CMakeTmp'
mingw32-make.exe: *** [Makefile:120: cmTC_838da/fast] Error 2
This is a freshly installed Windows 10 PC. It has no Visual Studio nor any Microsoft development tool installed on it. If possible I would prefer not having to install the Visual Studio for example to get the msvcrtd.lib. I am using VS Code at the moment, but this should be independent of the IDE being used.
My question is, what exactly do I have to install apart from LLVM, CMake and MinGW to make my first simple C++ project to build?
You are missing the libraries in the linker flag. These libraries may be found in the following location:
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x86
The exact path on your system may vary depending on the OS version etc., but you get the idea i believe. After finding the location you can add the path to the compiler flag in the CMakeLists.txt file e.g.,
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xlinker /libpath:path_to_library")
See related answers:
https://software.intel.com/en-us/forums/intel-fortran-compiler/topic/784047
https://stackoverflow.com/a/48576249/811335
How /libpath flag is used:
https://learn.microsoft.com/en-us/cpp/build/reference/libpath-additional-libpath?view=vs-2019
To force Clang to use its own libraries instead of MSVC's, add "-target x86_64-w64-mingw32" to CMAKE_C(XX)_FLAGS.
Beware: you have to do this before CMake identifies the compiler, e.g. either before the first C or C++ project definition in CMake (e.g. before the project() call):
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target x86_64-w64-mingw32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target x86_64-w64-mingw32")
project(MyProject ...)
Alternatively, you can pass it with "-D" to CMake on the command line.
Tested with clang 10.0
If I remember correctly, Clang attempts to use MSVC's standard library on Windows by default, since Clang's own standard library doesn't work on Windows yet.
If you don't have MSVC installed, this causes problems.
The easiest solution is to install MSYS2 and use MSYS2's patched Clang, which uses GCC's libraries by default. As a nice bonus, MSYS2 also comes with an up-to-date GCC version.
Alternatively, you can use -target flag to tell Clang to use GCC's libraries. If I remember correctly, this is done by adding -target x86_64-w64-mingw32 to both compiler and linker flags.
(If it doesn't work, try -target x86_64-w64-windows-gnu, I can't remember which one it is. Replace x86_64 with i686 if you're using a 32-bit compiler.)
Your Clang compiler is probably built to target the MSVC ABI. If I try your scenario, this is my error message:
-- The CXX compiler identification is Clang 9.0.0
CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:802 (message): The Clang compiler tool
"C:/Program Files/LLVM/bin/clang++"
targets the MSVC ABI but has a GNU-like command-line interface. This is not supported. Use 'clang-cl' instead, e.g. by setting 'CXX=clang-cl' in the environment. Furthermore, use the MSVC command-line environment.
This was with CMake 3.13 and LLVM 9.0, and trying to use -G "MinGW Makefiles". It works using this:
SET CXX="C:/Program Files/LLVM/bin/clang-cl.exe"
cmake -G "NMake Makefiles" ..
You probably don't need to install Visual Studio, but if you want to use nmake and the MSVC libraries, you definitely need the Windows 10 SDK which is a big download, and it will be installed as well if you decide to install Visual Studio.
On the other hand, The problem seems to be related to the CMake 3.16 version. The above unsucessful tests were made with cmake 3.13, but after that I've upgraded to CMake 3.15.5 and it works perfectly. Here are the exact versions:
> cmake -version
cmake version 3.15.5
> clang++ --version
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
My build.cmd script:
SET CXX="C:/Program Files/LLVM/bin/clang++.exe"
cmake -G "MinGW Makefiles" ..
So the problem may be with your CMake version, or the MinGW libraries, as your error message is suggesting.

Building ASSIMP with MinGW causes file too big error

I am building ASSIMP using cmake and mingw-w64 on windows 10 and it gives me "file too big" errors while creating the object code. I tried using MinGW and MinGW-w64 and both give me the same error. I am using the default settings, I configure the project with cmake, generate the makefile and then run mingw32-make. Is there some kind of flag I can set to fix this?
Compiler:
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Here is the output:
[ 59%] Building CXX object code/CMakeFiles/assimp.dir/Importer/StepFile/StepFileImporter.cpp.obj
[ 60%] Building CXX object code/CMakeFiles/assimp.dir/Importer/StepFile/StepFileGen1.cpp.obj
C:/mingw-w64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe:
CMakeFiles\assimp.dir\Importer\StepFile\StepFileGen1.cpp.obj: section .xdata$_ZNSt10_Head_baseILy0EPN6Assimp8StepFile29directed_dimensional_locationELb0EE7_M_headERKS4_:
string table overflow at offset 10000029
C:\Users\ANDREW~1.NOT\AppData\Local\Temp\ccwwseVM.s: Assembler messages:
C:\Users\ANDREW~1.NOT\AppData\Local\Temp\ccwwseVM.s: Fatal error: can't close CMakeFiles\assimp.dir\Importer\StepFile\StepFileGen1.cpp.obj: File too big
mingw32-make[2]: *** [code\CMakeFiles\assimp.dir\build.make:2485: code/CMakeFiles/assimp.dir/Importer/StepFile/StepFileGen1.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:274: code/CMakeFiles/assimp.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2
EDIT: I was using the master branch of Assimp from github, which has newer experimental features. I downloaded an older release version and I did not get the same errors.
This error is fixed by assimp itself https://github.com/assimp/assimp/issues/2406 Which version do you use?
What worked for me :
Go into the CMakeLists.txt and add:
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-O3")
Then compile with some options off:
cmake .. -G "Unix Makefiles" -DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_BUILD_TESTS=OFF
make -j4 && make install
It worked for 5.0.0-rc1 and 5.0.1 too.