Qt5中的Cuda Link错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt5中的Cuda Link错误相关的知识,希望对你有一定的参考价值。
我开始在Qt5.8中使用Cuda 8.0,在Windows 10上使用Qt创建者和Visual Studio 2015 x64,我得到了未解析的符号,如:
cuda_code_cuda.o : error LNK2019: 澷朄夝愅揑奜晹晞崋 atexit丆
cuda_code_cuda.o : error LNK2019: 澷朄夝愅揑奜晹晞崋 cudaDeviceSynchronize丆
cuda_code_cuda.o : error LNK2019: 澷朄夝愅揑奜晹晞崋 cudaConfigureCall丆
cuda_code_cuda.o : error LNK2019: 澷朄夝愅揑奜晹晞崋 cudaSetupArgument丆
cuda_code_cuda.o : error LNK2019: 澷朄夝愅揑奜晹晞崋 cudaLaunch丆
cuda_code_cuda.o : error LNK2019: 澷朄夝愅揑奜晹晞崋 __imp_fminf丆
...
我的.pro文件看起来像:
QT += core
QT -= gui
CONFIG += c++11
TARGET = QtWithCuda
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
#-------------------------------------------------
# CUDA settings
CUDA_SOURCES += cuda_code.cu
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/"
SYSTEM_NAME = x64
SYSTEM_TYPE = 64
CUDA_ARCH = compute_50
CUDA_CODE = sm_50
NVCC_OPTIONS = --use_fast_math
# include paths
INCLUDEPATH += "$$CUDA_DIR/include"
# library directories
QMAKE_LIBDIR += "C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0libx64"
"E:Program Files (x86)Microsoft Visual Studio 14.0VCatlmfclibamd64"
"E:Program Files (x86)Microsoft Visual Studio 14.0VClibamd64"
"C:Program Files (x86)Windows Kits10lib10.0.10240.0ucrtx64"
# "C:Program Files (x86)Windows Kits8.1libwinv6.3umx64"
"C:Program Files (x86)Windows Kits10Lib10.0.10240.0umx64"
"C:Program Files (x86)Windows KitsNETFXSDK4.6.1Libumx64"
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
# Add the necessary libraries
CUDA_LIB_NAMES +=
cuda
cudart
kernel32
user32
gdi32
winspool
comdlg32
advapi32
shell32
ole32
oleaut32
uuid
odbc32
odbccp32
ucrt
for(lib, CUDA_LIB_NAMES) {
CUDA_LIBS += $$lib.lib
}
for(lib, CUDA_LIB_NAMES) {
NVCC_LIBS += -l$$lib
}
LIBS += $$CUDA_LIBS
# The following library conflicts with something in Cuda
QMAKE_LFLAGS_RELEASE = /NODEFAULTLIB:msvcrt.lib
QMAKE_LFLAGS_DEBUG = /NODEFAULTLIB:msvcrtd.lib
# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"
# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
# Debug mode
DESTDIR = debug
OBJECTS_DIR = debug/obj
CUDA_OBJECTS_DIR = debug/cuda
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS
--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -code=$$CUDA_CODE
--compile -cudart static -g -DWIN32 -D_MBCS
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/Od,/Zi,/RTC1"
-Xcompiler $$MSVCRT_LINK_FLAG_DEBUG
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release mode
DESTDIR = release
OBJECTS_DIR = release/obj
CUDA_OBJECTS_DIR = release/cuda
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS
--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -code=$$CUDA_CODE
#--use-local-env --cl-version 2015 -ccbin "E:Program Files (x86)Microsoft Visual Studio 14.0VCinx86_amd64"
--compile -cudart static -D_MBCS
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi"
-Xcompiler $$MSVCRT_LINK_FLAG_RELEASE
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
我已经阅读了一些关于在qt上配置cuda的线程,但似乎没有人得到像这样的错误。我复制了VS示例链接器设置中出现的所有lib文件,但仍然得到错误。我该怎么办?
答案
我现在解决了这个问题,这是通过将msvcrt添加到lib列表中来实现的。想知道为什么此文件未在示例Visual Studio项目中列出。
以上是关于Qt5中的Cuda Link错误的主要内容,如果未能解决你的问题,请参考以下文章
ubuntu 16.04 + N驱动安装 +CUDA+Qt5 + opencv
CUDA 11 中的链接时优化 - 它们是啥以及如何使用它们?
RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor(代码片段