I try to build a CMake (v3.14) project with MSVC 2015. I use the CMake GUI to generate the makefile but when I hit the "Configure" button, I get the following error:
The C compiler identification is MSVC 19.0.24210.0
The CXX compiler identification is MSVC 19.0.24210.0
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Projets/geolibextern/build_msvc/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_fa317\fast
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe" -f CMakeFiles\cmTC_fa317.dir\build.make /nologo -L CMakeFiles\cmTC_fa317.dir\build
Building C object CMakeFiles/cmTC_fa317.dir/testCCompiler.c.obj
C:\PROGRA~2\MICROS~2.0\VC\bin\amd64\cl.exe #C:\Users\egrace\AppData\Local\Temp\nm88C7.tmp
testCCompiler.c
Linking C executable cmTC_fa317.exe
"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_fa317.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2.0\VC\bin\amd64\link.exe /nologo #CMakeFiles\cmTC_fa317.dir\objects1.rsp #C:\Users\egrace\AppData\Local\Temp\nm8993.tmp
RC Pass 1: command "rc /foCMakeFiles\cmTC_fa317.dir/manifest.res CMakeFiles\cmTC_fa317.dir/manifest.rc" failed (exit code 0) with the following output:
Le fichier sp‚cifi‚ est introuvableNMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
I also tried (unsuccessfully) to reinstall the Visual C++ build tools or to use a more recent version of CMake.
Indeed, CMake couldn't find the program mt.exe because the Windows SDK folder wasn't in the PATH variable. To solve this problem, I need to execute this command with these arguments:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 8.1
I've been trying to build some code using CMake via PowerShell(administrator).
I've run Microsoft Visual Studio 10.0\VC\vcvarsall.bat for setting environment variables.
I also set every environment variable required for this project (for CMake, BUILD_ROOT, etc).
Also, I've windows SDK version 8.0 and 8.1 in the system.
But, when I try to compile, I get a compiler broken error and a 'kernel32.lib' missing error, even though 'kernel32.lib' is there in the windows SDK path.
Can anyone provide me with a possible solution, please?
Attaching the PowerShell Output below:
> PS > C:\project\build-dir> cmake ..
> -DBUILD_CLASSIFIER=Windows-x64-VS100 -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" $env:BUILD_ROOT\3rd_Party\lib-6.5.1
-- The C compiler identification is MSVC 16.0.30319.1
-- The CXX compiler identification is MSVC 16.0.30319.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe - broken CMake Error at C:/Program
Files/CMake/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69
(message): The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/build-dir/CMakeFiles/CMakeTmp
Run Build Command(s):nmake -f Makefile /nologo cmTC_cefcc\fast && "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe"
-f CMakeFiles\cmTC_cefcc.dir\build.make /nologo -L CMakeFiles\cmTC_cefcc.dir\bu ild
Building C object CMakeFiles/cmTC_cefcc.dir/testCCompiler.c.obj
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_cefcc.dir\testCCom
piler.c.obj.d
--working-dir=C:\GITWS\CP.24.0_dev_New\print_server\CMService\colorToolKit\ctk-build\CMakeFiles\CMakeTmp -
-filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~4.0\VC\bin\cl.exe
#C:\Users\ADMINI~1.XER\AppData\Local\Tem p\nm8FBD.tmp
testCCompiler.c
Linking C executable cmTC_cefcc.exe
"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_cefcc.dir --rc=C:\PROGRA~2\MICROS ~1\Windows\v7.0A\Bin\RC.Exe
--mt=C:\PROGRA~2\MICROS~1\Windows\v7.0A\Bin\mt.exe --manifests -- C:\PROGRA~2\MICROS~4.0\VC\ bin\link.exe /nologo
#CMakeFiles\cmTC_cefcc.dir\objects1.rsp
#C:\Users\ADMINI~1.XER\AppData\Local\Temp\nm904A.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~4.0\VC\bin\link.exe /nologo #CMakeFiles\cmTC_cefcc.dir\objects1.rsp /out:cm TC_cefcc.exe
/implib:cmTC_cefcc.lib
/pdb:C:\GITWS\CP.24.0_dev_New\print_server\CMService\colorToolKit\ctk-build\CMakeFil
es\CMakeTmp\cmTC_cefcc.pdb /version:0.0 /machine:X86 /debug
/INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi3
2.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFi
les\cmTC_cefcc.dir/intermediate.manifest
CMakeFiles\cmTC_cefcc.dir/manifest.res" failed (exit code 1104) with
the follow ing output:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe"' : return code '0 x2'
Stop.
CMake will not be able to correctly generate this project. Call
Stack (most recent call first): CMakeLists.txt:4 (PROJECT)
-- Configuring incomplete, errors occurred! See also "C:/project/build-dir/CMakeFiles/CMakeOutput.log". See also
"C:/project/build-dir/CMakeFiles/CMakeError.log".
I'm trying to build some C++ libraries using cmake using the VS2017 developer command prompt. I need to build them for a Release x64 setup, however, the command prompt only seems to build them to x86.
First, I run this command (note the build type Release64):
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release64 -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=../../../../install ../..
-- The C compiler identification is MSVC 19.16.27039.0
-- The CXX compiler identification is MSVC 19.16.27039.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- 3.13.0.0
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/test_game_server/protobuf/cmake/build/release64
Then I run nmake, but I see this error:
...
[ 49%] Linking CXX static library gmock_main.lib
[ 49%] Built target gmock_main
[ 50%] Generating C:/test_game_server/protobuf/src/google/protobuf/any_test.pb.cc
google/protobuf/any_test.pb.cc: while trying to create directory C:/test_game_server/protobuf/src/google: No error
NMAKE : fatal error U1077: '.\protoc.exe' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
This error still occurred even after I used Vcvarsall.bat to set a 64-bit hosted build architecture:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.22
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
It is worth noting that there are no errors when I compile the project with the option Release instead of Release64.
I looked for the x64 native or cross-tool developer command prompts, but I don't have any associated with VS2017 (I do have one for VS2010 but the C++ version is out of date). Compiling in my standard Windows command prompt is not an option.
How can I force this project to compile to x64 instead of x86?
If you do not require using NMake, you could use the Visual Studio's build system by first generating for 64 bit (note the Win64 part):
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release64 -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=../../../../install ../..
And then building via cmake's build command:
cmake --build <directory> --config Release64
CMake will then generate and execute whatever command is needed for building using Visual Studio itself on the command line.
You aren't using CMAKE_BUILD_TYPE properly.
https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Unless you have defined a configuration besides the default ones (Debug, Release, RelWithDebInfo, MinSizeRel) what you are doing makes no sense.
Configurations have nothing to do with the architecture you are compiling for.
The architecture you are compiling for has to do with tool-chains and compiler options.
======================================
2nd
NMake Makefiles are ridiculously slow. Use Ninja or Visual Studio instead.
======================================
3rd
Here are instructions for building for x64/x86 using visual studio (I use 2019, but it shouldn't matter)
cmake -G "Visual Studio 16 2019" -A Win32 -S path_to_source -B "build32"
cmake --build build32 --config Release
cmake -G "Visual Studio 16 2019" -A x64 -S path_to_source -B "build64"
cmake --build build64 --config Release
======================================
4th
If you wondering how to configure/build for single configuration generators like ninja/nmake-builds please open up another question. Because it's a loaded question.
The question has been updated sinces its original posting. I have kept everything for context and information for people in the future, but the latest information and issues are at the bottom.
I have found somewhat similar questions posted previously about related subjects, but none of them seemed to have a clear, concise resolution for what exactly I'm doing. I'm hoping that by asking this question, I can get an answer and there will also be a more clear answer available on the internet for future people with similar troubles.
I am trying to create a simple example C++ code using NetCDF in Visual Studio 2019 with CMake as the build system. I installed NetCDF using vcpkg, specifically the command
vcpkg install netcdf-cxx:x64-windows
which installed all prerequisite packages and netcdf-cxx:x64-windows to C:\Program Files\vcpkg\packages.
In the project itself, I have two main files: main.cpp and CMakeLists.txt. The directory structure is as follows:
- C:\
- Users\
- Owner\
- Education and Research\
- Personal Projects\
- learning_coding\
- C++\
- cmake_netcdf\
- CMakeLists.txt
- main.cpp
The file main.cpp is
#include <iostream>
#include <netcdf>
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
while CMakeLists.txt is
cmake_minimum_required (VERSION 3.17)
project(cmake_netcdf)
# Add source to this project's executable.
add_executable(cmake_netcdf main.cpp)
# Find and include the netcdf package
find_package(netcdf CONFIG REQUIRED)
target_link_libraries(cmake_netcdf
PRIVATE netcdf
)
Visual Studio can successfully refresh C++ IntelliSense information,
1> CMake generation started for configuration: 'x64-Debug'.
1> Found and using vcpkg toolchain file (C:/Program Files/vcpkg/scripts/buildsystems/vcpkg.cmake).
1> The toolchain file has changed (CMAKE_TOOLCHAIN_FILE).
1> Command line: "cmd.exe" /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" -DCMAKE_TOOLCHAIN_FILE="C:/Program Files/vcpkg/scripts/buildsystems/vcpkg.cmake" "C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf" 2>&1"
1> Working directory: C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.27.29111.0
1> [CMake] -- The CXX compiler identification is MSVC 19.27.29111.0
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - works
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
1> [CMake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - works
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Found ZLIB: optimized;C:/Program Files/vcpkg/installed/x64-windows/lib/zlib.lib;debug;C:/Program Files/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (found version "1.2.11")
1> [CMake] -- Found ZLIB: optimized;C:/Program Files/vcpkg/installed/x64-windows/lib/zlib.lib;debug;C:/Program Files/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (found suitable version "1.2.11", minimum required is "1")
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: C:/Users/Owner/Education and Research/Personal Projects/learning_coding/C++/cmake_netcdf/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted includes paths.
1> CMake generation finished.
but the project fails to build and gives the error messages cannot open source file "netcdf" and Cannot open include file: 'netcdf': No such file or directory. How can I fix this error?
EDIT 1: Following up on the comments:
"Can you check in the Solution Properties->Include Directories whether the path to the netcdf include is set?" – user3389943
This code isn't saved as a solution, but you did prompt me to look at the CMake variables. The directory variable for netcdf is netcdf_DIR = C:/Program Files/vcpkg/installed/x64-windows/share/netcdf-c, which looks like
- C:/Program Files/vcpkg/installed/x64-windows/share/netcdf-c/
- copyright
- netCDFConfig.cmake
- netCDFConfigVersion.cmake
- netCDFTargets.cmake
- netCDFTargets-debug.cmake
- netCDFTargets-release.cmake
- usage
- vcpkg_abi_info.txt
There is not variable for netcdf_INCLUDES or anything of that sort. Is it an issue that it's looking at netcdf-c for a C++ program? How do I get CMake to look for the proper include directories?
"There is no header named netcdf in the NetCDF package. It should read #include "netcdf.h"." – vre
Making that change does not fix the error, it gives the same error replacing 'netcdf' with "netcdf.h". I think the proper include is netcdf, unless the tutorials are out-of-date.
EDIT 2: Following up on the comments:
""I think the proper include is netcdf": The include file is definitely named netcdf.h. Your find_package call should try to find netCDF, case matters here. In the netCDFTargets-debug.cmake there is a target defined with add_library(<> IMPORTED ...). Use this target name for your target_link_libraries command." – vre
Thank you for telling me about this file! The file netCDFTargets-debug.cmake reads
#----------------------------------------------------------------
# Generated CMake target import file for configuration "DEBUG".
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Import target "netCDF::netcdf" for configuration "DEBUG"
set_property(TARGET netCDF::netcdf APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(netCDF::netcdf PROPERTIES
IMPORTED_IMPLIB_DEBUG "${_IMPORT_PREFIX}/debug/lib/netcdf.lib"
IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/debug/bin/netcdf.dll"
)
list(APPEND _IMPORT_CHECK_TARGETS netCDF::netcdf )
list(APPEND _IMPORT_CHECK_FILES_FOR_netCDF::netcdf "${_IMPORT_PREFIX}/debug/lib/netcdf.lib" "${_IMPORT_PREFIX}/debug/bin/netcdf.dll" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
So I changed my CMakeLists.txt to
# Unit test for building a program with netCDF using CMake in visual studio.
cmake_minimum_required (VERSION 3.17)
project(cmake_netcdf)
# Add source to this project's executable.
add_executable(cmake_netcdf main.cpp)
# Find and include the netcdf package
find_package(netCDF CONFIG REQUIRED)
target_link_libraries(cmake_netcdf
PRIVATE netCDF::netcdf
)
and now main.cpp builds! It builds using both #include <netcdf> and #include "netcdf.h".
From here, I decided to change main.cpp to an example file on NCAR's website, so main.cpp now is
/* This is part of the netCDF package.
Copyright 2006 University Corporation for Atmospheric Research/Unidata.
See COPYRIGHT file for conditions of use.
This is a very simple example which writes a 2D array of
sample data. To handle this in netCDF we create two shared
dimensions, "x" and "y", and a netCDF variable, called "data".
This example is part of the netCDF tutorial:
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial
Full documentation of the netCDF C++ API can be found at:
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-cxx
$Id: simple_xy_wr.cpp,v 1.5 2010/02/11 22:36:43 russ Exp $
*/
#include <iostream>
#include <netcdf>
#include <vector>
using namespace std;
using namespace netCDF;
using namespace netCDF::exceptions;
// We are writing 2D data, a 6 x 12 grid.
static const int NX = 6;
static const int NY = 12;
// Return this in event of a problem.
static const int NC_ERR = 2;
int main()
{
// This is the data array we will write. It will just be filled
// with a progression of numbers for this example.
int dataOut[NX][NY];
// Create some pretend data. If this wasn't an example program, we
// would have some real data to write, for example, model output.
for (int i = 0; i < NX; i++)
for (int j = 0; j < NY; j++)
dataOut[i][j] = i * NY + j;
// The default behavior of the C++ API is to throw an exception i
// an error occurs. A try catch block is necessary.
try
{
// Create the file. The Replace parameter tells netCDF to overwrite
// this file, if it already exists.
NcFile dataFile("simple_xy.nc", NcFile::replace);
// Create netCDF dimensions
NcDim xDim = dataFile.addDim("x", NX);
NcDim yDim = dataFile.addDim("y", NY);
// Define the variable. The type of the variable in this case is
// ncInt (32-bit integer).
vector<NcDim> dims;
dims.push_back(xDim);
dims.push_back(yDim);
NcVar data = dataFile.addVar("data", ncInt, dims);
// Write the data to the file. Although netCDF supports
// reading and writing subsets of data, in this case we write all
// the data in one operation.
data.putVar(dataOut);
// The file will be automatically close when the NcFile object goes
// out of scope. This frees up any internal netCDF resources
// associated with the file, and flushes any buffers.
//cout << "*** SUCCESS writing example file simple_xy.nc!" << endl;
return 0;
}
catch (NcException& e)
{
e.what();
return NC_ERR;
}
}
When trying to build this example file, I get a bunch of linker errors
>------ Build All started: Project: cmake_netcdf, Configuration: x64-Debug ------
[1/2] Building CXX object CMakeFiles\cmake_netcdf.dir\main.cpp.obj
[2/2] Linking CXX executable cmake_netcdf.exe
FAILED: cmake_netcdf.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\cmake_netcdf.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmake_netcdf.dir\main.cpp.obj /out:cmake_netcdf.exe /implib:cmake_netcdf.lib /pdb:cmake_netcdf.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console "C:\Program Files\vcpkg\installed\x64-windows\debug\lib\netcdf.lib" "C:\Program Files\vcpkg\installed\x64-windows\debug\lib\hdf5_hl_D.lib" "C:\Program Files\vcpkg\installed\x64-windows\debug\lib\hdf5_D.lib" "C:\Program Files\vcpkg\installed\x64-windows\debug\lib\libcurl-d.lib" "C:\Program Files\vcpkg\installed\x64-windows\debug\lib\zlibd.lib" wldap32.lib winmm.lib ws2_32.lib advapi32.lib crypt32.lib advapi32.lib crypt32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D "C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug" && powershell -noprofile -executionpolicy Bypass -file "C:/Program Files/vcpkg/scripts/buildsystems/msbuild/applocal.ps1" -targetBinary "C:/Users/Owner/Education and Research/Personal Projects/learning_coding/C++/cmake_netcdf/build/x64-Debug/cmake_netcdf.exe" -installedDir "C:/Program Files/vcpkg/installed/x64-windows/debug/bin" -OutVariable out""
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmake_netcdf.dir\main.cpp.obj /out:cmake_netcdf.exe /implib:cmake_netcdf.lib /pdb:cmake_netcdf.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\Program Files\vcpkg\installed\x64-windows\debug\lib\netcdf.lib C:\Program Files\vcpkg\installed\x64-windows\debug\lib\hdf5_hl_D.lib C:\Program Files\vcpkg\installed\x64-windows\debug\lib\hdf5_D.lib C:\Program Files\vcpkg\installed\x64-windows\debug\lib\libcurl-d.lib C:\Program Files\vcpkg\installed\x64-windows\debug\lib\zlibd.lib wldap32.lib winmm.lib ws2_32.lib advapi32.lib crypt32.lib advapi32.lib crypt32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmake_netcdf.dir/intermediate.manifest CMakeFiles\cmake_netcdf.dir/manifest.res" failed (exit code 1120) with the following output:
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl netCDF::NcDim::NcDim(class netCDF::NcDim const &)" (??0NcDim#netCDF##QEAA#AEBV01##Z) referenced in function "public: static void __cdecl std::_Default_allocator_traits<class std::allocator<class netCDF::NcDim> >::construct<class netCDF::NcDim,class netCDF::NcDim &>(class std::allocator<class netCDF::NcDim> &,class netCDF::NcDim * const,class netCDF::NcDim &)" (??$construct#VNcDim#netCDF##AEAV12##?$_Default_allocator_traits#V?$allocator#VNcDim#netCDF###std###std##SAXAEAV?$allocator#VNcDim#netCDF###1#QEAVNcDim#netCDF##AEAV34##Z)
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: class netCDF::NcVar __cdecl netCDF::NcGroup::addVar(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class netCDF::NcType const &,class std::vector<class netCDF::NcDim,class std::allocator<class netCDF::NcDim> > const &)const " (?addVar#NcGroup#netCDF##QEBA?AVNcVar#2#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEBVNcType#2#AEBV?$vector#VNcDim#netCDF##V?$allocator#VNcDim#netCDF###std###5##Z) referenced in function main
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: class netCDF::NcDim __cdecl netCDF::NcGroup::addDim(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned __int64)const " (?addDim#NcGroup#netCDF##QEBA?AVNcDim#2#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_K#Z) referenced in function main
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl netCDF::NcFile::NcFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum netCDF::NcFile::FileMode)" (??0NcFile#netCDF##QEAA#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##W4FileMode#01##Z) referenced in function main
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl netCDF::NcFile::~NcFile(void)" (??1NcFile#netCDF##UEAA#XZ) referenced in function main
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl netCDF::NcVar::putVar(void const *)const " (?putVar#NcVar#netCDF##QEBAXPEBX#Z) referenced in function main
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\main.cpp.obj : error LNK2001: unresolved external symbol "class netCDF::NcInt netCDF::ncInt" (?ncInt#netCDF##3VNcInt#1#A)
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\build\x64-Debug\cmake_netcdf.exe : fatal error LNK1120: 7 unresolved externals
ninja: build stopped: subcommand failed.
Build All failed.
I tried replacing #include <netcdf> with #include "netcdf.h" but I got even more errors:
[1/2] Building CXX object CMakeFiles\cmake_netcdf.dir\main.cpp.obj
FAILED: CMakeFiles/cmake_netcdf.dir/main.cpp.obj
C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\cl.exe /nologo /TP -DDEBUG -DH5_BUILT_AS_DYNAMIC_LIB -I"C:\Program Files\vcpkg\installed\x64-windows\include" /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /FoCMakeFiles\cmake_netcdf.dir\main.cpp.obj /FdCMakeFiles\cmake_netcdf.dir\ /FS -c ..\..\main.cpp
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(22): error C2871: 'netCDF': a namespace with this name does not exist
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(23): error C2653: 'netCDF': is not a class or namespace name
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(23): error C2871: 'exceptions': a namespace with this name does not exist
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(53): error C2065: 'NcFile': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(53): error C2146: syntax error: missing ';' before identifier 'dataFile'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(53): error C2653: 'NcFile': is not a class or namespace name
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(53): error C2065: 'replace': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(53): error C3861: 'dataFile': identifier not found
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(56): error C2065: 'NcDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(56): error C2146: syntax error: missing ';' before identifier 'xDim'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(56): error C2065: 'xDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(56): error C2065: 'dataFile': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(57): error C2065: 'NcDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(57): error C2146: syntax error: missing ';' before identifier 'yDim'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(57): error C2065: 'yDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(57): error C2065: 'dataFile': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(61): error C2065: 'NcDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(61): error C2923: 'std::vector': 'NcDim' is not a valid template type argument for parameter '_Ty'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(61): error C2976: 'std::vector': too few template arguments
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\vector(413): note: see declaration of 'std::vector'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(61): error C2133: 'dims': unknown size
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(61): error C2512: 'std::vector': no appropriate default constructor available
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\vector(413): note: see declaration of 'std::vector'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(62): error C2065: 'xDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(63): error C2065: 'yDim': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(64): error C2065: 'NcVar': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(64): error C2146: syntax error: missing ';' before identifier 'data'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(64): error C2065: 'dataFile': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(64): error C2065: 'ncInt': undeclared identifier
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(78): error C2061: syntax error: identifier 'NcException'
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(78): error C2310: catch handlers must specify one type
C:\Users\Owner\Education and Research\Personal Projects\learning_coding\C++\cmake_netcdf\main.cpp(80): error C2065: 'e': undeclared identifier
ninja: build stopped: subcommand failed.
Build All failed.
Any insight on these new issues? A Google search brought me to this page which suggests that CMake is linking against a 32-bit version of the library (whereas my system is 64 bit), but I only have the 64-bit version of the library installed.
Also, with regards to #include <netcdf> versus #include "netcdf.h", I have both files in C:\Program Files\vcpkg\installed\x64-windows\include (along with a bunch of header files related to HDF5 and stuff). It seems like <netcdf> is the whole thing while netcdf.h is just part of it?
"netcdf_DIR is where find_package searches for the headers and libraries. Can you cross check the target name as #vre mentioned?" – user3389943
I certainly can! netcdf_DIR is C:/Program Files/vcpkg/installed/x64-windows/share/netcdf-c, which I mentioned the contents of in Edit 1.
The netCDFTargets.cmake file has the line add_library(netCDF::netcdf SHARED IMPORTED), which I used for the newest version of the target_link_libraries command.
EDIT 3: Following up on the comments:
"So what other targets are defined in netCDFTargets.cmake" – user3389943
I'm not entirely sure how to parse netCDFTargets.cmake, so here are the contents:
# Generated by CMake
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget netCDF::netcdf)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()
# Create imported target netCDF::netcdf
add_library(netCDF::netcdf SHARED IMPORTED)
set_target_properties(netCDF::netcdf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB;hdf5::hdf5-shared;hdf5::hdf5_hl-shared;CURL::libcurl"
)
if(CMAKE_VERSION VERSION_LESS 2.8.12)
message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.")
endif()
# Load information for each installed configuration.
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/netCDFTargets-*.cmake")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()
# Cleanup temporary variables.
set(_IMPORT_PREFIX)
# Loop over all imported files and verify that they actually exist
foreach(target ${_IMPORT_CHECK_TARGETS} )
foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )
if(NOT EXISTS "${file}" )
message(FATAL_ERROR "The imported target \"${target}\" references the file
\"${file}\"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
\"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
endif()
endforeach()
unset(_IMPORT_CHECK_FILES_FOR_${target})
endforeach()
unset(_IMPORT_CHECK_TARGETS)
# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
Does that help?
Alright, I found a solution! It most certainly is not a perfect solution, but it is a solution.
Unfortunately, I was not able to get it to work on Visual Studio with Windows. I will probably try again at some point, but I think the version of netCDF-cxx4 is out of date on vcpkg or something. I am currently away from my primary work station, so I will have to try again on there to see if I can get a solution in Visual Studio. Anyway, here's what I did that seemed to work:
I downloaded Ubuntu 20.04.1 via the Windows Subsystem for Linux (WSL). I'm not sure if this will work for older or newer versions of Ubuntu, but I assume that it will. I also am using the Windows Terminal that they mention on that page and set up my colors with the vimrc example file found here.
This changes how your file system works a bit by adding two layers above C:\, which are /mnt/. You can navigate to your files on Windows by going to /mnt/c/Users/ and to the Ubuntu subsystem by going to /. I named my Ubuntu account usr, so the 'desktop' Ubuntu files are kept in /home/usr. For all of the subsequent steps, I am using the Ubuntu terminal window in the Windows Terminal application.
There was also an issue with installing zlib via vcpkg after enabling WSL, but I don't know how to resolve it nor have I found a solution anywhere.
I downloaded a C++ compiler by running sudo apt install build-essential, and installed CMake and netCDF-C via sudo apt install cmake libnetcdf-dev.
I installed netCDF-cxx4 by cloning their GitHub repository to my home directory /home/usr and using the commands
mkdir build
cd build
cmake ..
make
ctest
sudo make install
If you don't have that sudo there, you'll get a permissions error.
I found the netCDFCxxConfig.cmake file in the directory /usr/local/lib/cmake/netcdf and made some changes to the CMakeLists.txt file
cmake_minimum_required(VERSION 3.8)
# Set project name and version
project(cmake_netcdfcxx4)
# Find the netcdf-cxx4 library
list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib/cmake/netCDF")
find_package(netCDFCxx REQUIRED)
# Add source to this project's executable.
add_executable(cmake_netcdfcxx4 main.cpp)
# Link the netcdf-cxx4 library to the executable
target_link_libraries(cmake_netcdfcxx4
PRIVATE
netCDF::netcdf-cxx4
)
to add this directory to the CMAKE_PREFIX_PATH variable. I'm still looking into how to add the directory /usr/local/lib/cmake/ to the CMake search path automatically so the user doesn't have to edit the CMakeLists.txt file to compile this properly, so I guess this will require some updating.
I hope this helps people in the future!
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