gpt4 book ai didi

c - 尝试设置 QT Creator 和 Cuda 时“链接器输入文件未使用,因为链接未完成”

转载 作者:太空宇宙 更新时间:2023-11-03 23:33:08 24 4
gpt4 key购买 nike

我正在尝试使用 QT Creator 作为 IDE 开始使用 C 和 Cuda。不幸的是,我从一开始就遇到了问题,并且不确定它来自哪里(如果它逐渐开始,它会更容易识别)。

我基本上已经安装了 CUDA(和 c)并运行了小的测试程序,但我想使用 IDE,所以我按照以下说明安装了 QT Creator:http://cudaspace.wordpress.com/2011/04/07/qt-creator-cuda-linux/但是我在运行示例时遇到错误:“链接器输入文件未使用,因为链接未完成”

这是所有文件(由于我使用的是 mac 并且说明适用于 linux,因此我进行了修改。我可以编译基本的 hello world 类型的东西,但出于某种原因不能编译示例):my_first_project.pro:

TEMPLATE = app
LANGUAGE = C++
CONFIG += qt4


SOURCES += main.cpp \
cuda_interface.cu
# Cuda sources
CUDA_SOURCES += cuda_interface.cu
# Project dir and outputs
PROJECT_DIR = $$system(pwd)
OBJECTS_DIR = $$PROJECT_DIR/Obj
DESTDIR = ../bin

# Path to cuda SDK install
CUDA_SDK = /Users/lostsoul/Dropbox/qt_cuda/C/
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda
# GPU architecture
CUDA_ARCH = compute_10
# nvcc flags (ptxas option verbose is always useful)
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# include paths
INCLUDEPATH += $$CUDA_DIR/include
INCLUDEPATH += $$CUDA_SDK/common/inc/
INCLUDEPATH += $$CUDA_SDK/../shared/inc/
# lib dirs
QMAKE_LIBDIR += $$CUDA_DIR/lib64
QMAKE_LIBDIR += $$CUDA_SDK/lib
QMAKE_LIBDIR += $$CUDA_SDK/common/lib
# libs - note than i'm using a x_86_64 machine
LIBS += -lcudart -lcutil_x86_64
# join the includes in a line
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
LD_LIBRARY_PATH = /usr/local/cuda/lib

# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o

cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -g -G -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

cuda.dependcy_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -g -G -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda

cuda_interface.cu:

// CUDA-C includes
#include <cuda.h>
#include <cutil_inline.h>

extern "C"
void runCudaPart();

// Main cuda function

void runCudaPart() {

// all your cuda code here *smile*

}

主要.cpp:

#include <QtCore/QCoreApplication>

// This is the 'elder trick of the...' - Tell the compiler this function is defined in other place
extern "C"
void runCudaPart();

int main(int argc, char *argv[]) {

QCoreApplication a(argc, argv);

runCudaPart();

return a.exec();

}

这是错误的输出:

09:24:27: Running build steps for project first_project...
09:24:27: Configuration unchanged, skipping qmake step.
09:24:27: Starting: "/usr/bin/make" -w
make: Entering directory `/Users/lostsoul/Dropbox/qt_cuda/first_project-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug'
/usr/local/cuda/bin/nvcc -m64 -g -G -arch=compute_10 -c --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v -I/usr/local/cuda/include -I/Users/lostsoul/Dropbox/qt_cuda/C//common/inc/ -I/Users/lostsoul/Dropbox/qt_cuda/C//../shared/inc/ -lcudart -lcutil_x86_64 ../first_project/cuda_interface.cu -o ../first_project/Obj/cuda_interface_cuda.o
g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++ -I../first_project -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include -I/usr/local/cuda/include -I../C/common/inc -I/Users/lostsoul/Dropbox/qt_cuda/C//../shared/inc/ -I. -I../first_project -I. -F/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -o ../first_project/Obj/main.o ../first_project/main.cpp
gcc -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++ -I../first_project -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include -I/usr/local/cuda/include -I../C/common/inc -I/Users/lostsoul/Dropbox/qt_cuda/C//../shared/inc/ -I. -I../first_project -I. -F/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -o ../first_project/Obj/cuda_interface.o ../first_project/cuda_interface.cu
i686-apple-darwin11-llvm-gcc-4.2: ../first_project/cuda_interface.cu: linker input file unused because linking not done
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o ../bin/first_project.app/Contents/MacOS/first_project ../first_project/Obj/cuda_interface_cuda.o ../first_project/Obj/main.o ../first_project/Obj/cuda_interface.o -F/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -L/usr/local/cuda/lib64 -L/Users/lostsoul/Dropbox/qt_cuda/C//lib -L/Users/lostsoul/Dropbox/qt_cuda/C//common/lib -L/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -lcudart -lcutil_x86_64 -framework QtGui -L/usr/local/pgsql/lib -L/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib -F/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib -framework QtCore
i686-apple-darwin11-llvm-g++-4.2: ../first_project/Obj/cuda_interface.o: No such file or directory
make: *** [../bin/first_project.app/Contents/MacOS/first_project] Error 1
make: Leaving directory `/Users/lostsoul/Dropbox/qt_cuda/first_project-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug'
09:24:33: The process "/usr/bin/make" exited with code 2.
Error while building project first_project (target: Desktop)
When executing build step 'Make'

过去几个小时我一直在努力解决这个问题,我真的不确定如何处理这个问题。我唯一想到的可能是我的 make 版本对于说明来说太新了(因为我遵循的教程是去年的)但命令似乎可以执行。我对 C/Cuda 和 QT 创建者真的很陌生,我唯一的目标是在 QT 上执行 c/c++ 和 cuda 代码(因为显然它可以以它们相互交谈和代码完成的方式进行编译)。我越深入就越不确定这个错误是 QT 错误还是 C 错误(我不认为它是 CUDA 特定的错误,因为我真的没有任何代码)。

请帮忙!

最佳答案

根据我们在聊天中的讨论,我们发现 CUDA SDK 安装目录存在问题,因此您可以通过删除 SDK 相关内容来简化 .pro 文件。

检查您的 CUDA SDK 安装目录 (/Developer/GPU\Computing/C) 的空白区域,这可能是问题的原因。

也就是说,使用最新的软件和 osx lion 的基本配置如下:

QT += core
QT -= gui

TARGET = cuda_sample
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
# Source files for C/C++ compiler
SOURCES += main.cpp
# project build directories
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# and C/C++ flags
QMAKE_CFLAGS_RELEASE =-O3
QMAKE_CXXFLAGS_RELEASE =-O3
# cuda source
CUDA_SOURCES += cuda_interface.cu
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib
# GPU architecture
CUDA_ARCH = sm_20
# NVCC flags
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# Path to libraries
LIBS += -lcudart -lcuda
# join the includes in a line
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

cuda.dependcy_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -O3 -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}

cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda

因为我们没有使用 CUDA SDK 库,所以从您的 cuda_interface.cu 文件中删除以下行

#include <cutil_inline.h> // remove this line from your file

就是这样。请记住运行 qmake 以获取 .pro 文件的更改。

关于c - 尝试设置 QT Creator 和 Cuda 时“链接器输入文件未使用,因为链接未完成”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10517660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com