Linking libraries in the visual studio toolchain
已回答
Hi,
I am trying to link cufft and cudda libraries in Clion Nova but I cannot get it to work.
For example -L cuffft in standard gnu toolchain.
Also trying to add directives at compilation time and also it does not work properly with the Visual Studio toolchain.
It works in the code but not at compilation time. I need to make the difference between Windows and Linux for intrinsic methods which are system dependent.
For example
#if defined (WINDOWS)
#endif
Where do I put the -DWINDOWS in the compilation command in the Build,Execution, Deployment→CMake setting or Build,Execution, Deployment→Toolchains
Is there a tutorial on how to do this in CLion-Nova.
Thanks,
F.
请先登录再写评论。
Hello!
If you work with a CMake project, please take a look at https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#link-libs and https://cmake.org/cmake/help/latest/command/target_link_libraries.html.
If you work with a CMake project and you want to add include directories, please take a look at https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#inc-dirs and https://cmake.org/cmake/help/latest/command/include_directories.html.
You need to use the add_definitions() command in your CMakeLists.txt (
add_definitions(-DWINDOWS)
).Ok Thanks,
I cannot get it to work here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.27)
project(SystemProgrammingCuda CUDA)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
add_definitions(-DWINDOWS -DCUDA)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(SOURCE_FILES
include/dataDeviceManag.cuh
include/Exception.cuh
include/Sockets.cuh
include/common.cuh
include/Sockets.cuh
include/GetPID.h
include/common_krnl.cuh
include/carte_mesh_3D.cuh
include/cuAtomics.cuh
include/timming.cuh
include/get_deviceQuery_gpu.cuh
include/get_systemQuery_cpu.cuh
include/cmdLine.cuh
include/resmap_Sizes.cuh
include/common_Helpr_gpu.cuh
include/deviceTools_gpu.cuh
utils/timming.cu
utils/cmdLine.cu
utils/get_deviceQuery_gpu.cu
utils/get_systemQuery_cpu.cu
utils/deviceTools_gpu.cu
src/Sockets.cu
src/GetPID.c
src/carte_mesh_3D.cu
src/dataDeviceManag.cu
src/resmap_Sizes.cu
src/common_Helpr_gpu.cu
src/common_krnl_gpu.cu
test_codes/cpu/testing_ChronoTime.cpp
global.cu
global.cuh
)
add_executable(SystemProgrammingCuda main.cu ${SOURCE_FILES})
include(FindPkgConfig)
find_package(cufft REQUIRED)
find_package(cufftXt REQUIRED)
include_directories(${CUFFT_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${CUFFT_LIBRARY})
set_target_properties(SystemProgrammingCuda PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
and in a subdirectory cmake in a file called FindCuFFT.cmake I have:
set(FIND_CUFFT_PATHS C:/Program Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v12.2)
find_path(CUFFT_INCLUDE_DIR cufft.h PATH_SUFFIXES include PATHS ${FIND_CUFFT_PATHS})
find_library(CUFFT_LIBRARY NAMES cufft PATH_SUFFIXES lib/x64 PATHS ${FIND_CUFFT_PATHS})
I do not know why this is not working?
F.
The link step throws this error message in CLion
[14/15] Linking CUDA executable CMakeFiles\SystemProgrammingCuda.dir\cmake_device_link.obj
main.cu.obj
timming.cu.obj
cmdLine.cu.obj
get_deviceQuery_gpu.cu.obj
get_systemQuery_cpu.cu.obj
deviceTools_gpu.cu.obj
Sockets.cu.obj
carte_mesh_3D.cu.obj
dataDeviceManag.cu.obj
resmap_Sizes.cu.obj
common_Helpr_gpu.cu.obj
common_krnl_gpu.cu.obj
global.cu.obj
cufft.lib
cudadevrt.lib
cudart_static.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
[15/15] Linking CUDA executable SystemProgrammingCuda.exe
FAILED: SystemProgrammingCuda.exe
cmd.exe /C "cd . && "C:\Users\Frederic\AppData\Local\Programs\CLion Nova\bin\cmake\win\x64\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\SystemProgrammingCuda.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\SystemProgrammingCuda.dir\main.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\timming.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\cmdLine.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\get_deviceQuery_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\get_systemQuery_cpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\deviceTools_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\Sockets.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\carte_mesh_3D.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\dataDeviceManag.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\resmap_Sizes.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\common_Helpr_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\common_krnl_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\global.cu.obj CMakeFiles\SystemProgrammingCuda.dir\cmake_device_link.obj /out:SystemProgrammingCuda.exe /implib:SystemProgrammingCuda.lib /pdb:SystemProgrammingCuda.pdb /version:0.0 /debug /INCREMENTAL "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\lib\x64\cufft.lib" cudadevrt.lib cudart_static.lib 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/v12.2/lib/x64" && cd ."
LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\SystemProgrammingCuda.dir\main.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\timming.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\cmdLine.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\get_deviceQuery_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\get_systemQuery_cpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\utils\deviceTools_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\Sockets.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\carte_mesh_3D.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\dataDeviceManag.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\resmap_Sizes.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\common_Helpr_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\src\common_krnl_gpu.cu.obj CMakeFiles\SystemProgrammingCuda.dir\global.cu.obj CMakeFiles\SystemProgrammingCuda.dir\cmake_device_link.obj /out:SystemProgrammingCuda.exe /implib:SystemProgrammingCuda.lib /pdb:SystemProgrammingCuda.pdb /version:0.0 /debug /INCREMENTAL C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\lib\x64\cufft.lib cudadevrt.lib cudart_static.lib 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/v12.2/lib/x64 /MANIFEST /MANIFESTFILE:CMakeFiles\SystemProgrammingCuda.dir/intermediate.manifest CMakeFiles\SystemProgrammingCuda.dir/manifest.res" failed (exit code 1120) with the following output:
LINK : SystemProgrammingCuda.exe not found or not built by the last incremental link; performing full link
Creating library SystemProgrammingCuda.lib and object SystemProgrammingCuda.exp
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
main.cu.obj : error LNK2019: unresolved external symbol cuCtxSynchronize referenced in function main
SystemProgrammingCuda.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
Hi Anna,
OK I got it to work. I needed to move the
find_path(CUFFT_INCLUDE_DIR cufft.h PATH_SUFFIXES include PATHS ${FIND_CUFFT_PATHS})
find_library(CUFFT_LIBRARY NAMES cufft PATH_SUFFIXES lib/x64 PATHS ${FIND_CUFFT_PATHS})
find_path(CUFFTXT_INCLUDE_DIR cufftXt.h PATH_SUFFIXES include PATHS ${FIND_CUFFTXT_PATHS})
find_library(CUFFTXT_LIBRARY NAMES cufftXt PATH_SUFFIXES lib/x64 PATHS ${FIND_CUFFTXT_PATHS})
Directly into the CMakeLists.txt instread and it seems to work.
I am still having issues with the CUFFTXT lib. I think that I need to have these flags in the compoilation as well
-Xcompiler for the nvcc compiler.
NVCCFLAGS= --ptxas-options=-v $(PUSHMEM_GPU) -O3 -DADD_ -DBENCH -DCUDA \
-DMAGMA -DGSL
NVCCFLAGS+= -m${TARGET_SIZE} -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler \
-fPIC $(COMMON_FLAGS)
Do those flags go in the place as the directives
add_definitions(-DWINDOWS -DCUDA)
?
Thanks,
F.
Does https://www.jetbrains.com/help/clion/cuda-projects.html#set-nvcc help?