没有规则可以使目标Cuda + Qt + Linux

时间:2019-03-06 06:51:08

标签: linux qt makefile compilation cuda

尝试编译qt + cuda + linux并得到此错误“没有规则使目标'cuda_code.o'成为'../Test/Obj/cuda_code_cuda.o'。Stop。所需要的。”,但是我会做所有的事情逐步按照说明进行操作,只是不明白出了什么问题。我使用Ubuntu 18.10,Cuda编译工具V10.1.105和QT Creator 4.8.1。

main.cpp

#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;
// the next 'include' is for CUDA error checks
#include <cuda_runtime.h>
// This is the 'elder trick of the...' - Tell the compiler this function is defined in other place
extern "C"
cudaError_t cuda_main();

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

    // run your cuda application
    cudaError_t cuerr = cuda_main();
    // check for errors is always a good practice!
    if (cuerr != cudaSuccess) cout << "CUDA Error: " << cudaGetErrorString( cuerr ) << endl;

    return a.exec();
}

cuda_code.cu

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
extern "C"
cudaError_t cuda_main()
{
    // generate 16M random numbers on the host
    thrust::host_vector<int> h_vec(1 << 24);
    thrust::generate(h_vec.begin(), h_vec.end(), rand);

    // transfer data to the device
    thrust::device_vector<int> d_vec = h_vec;

    // sort data on the device (805 Mkeys/sec on GeForce GTX 480)
    thrust::sort(d_vec.begin(), d_vec.end());

    // transfer data back to host
    thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());

    return cudaGetLastError();
}

和Test.pro文件

QT       += core
QT       -= gui
TARGET    = QtCuda
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE  = app
SOURCES  += main.cpp\
cuda_code.cu
SOURCES -= cuda_code.cu
DESTDIR     = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
QMAKE_CXXFLAGS_RELEASE =-O3
CUDA_SOURCES += cuda_code.cu
CUDA_DIR      = /usr/local/cuda-10.1
INCLUDEPATH  += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib64
LIBS += -lcudart -lcuda
CUDA_ARCH     = sm_52
NVCCFLAGS     = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS \
                $$CUDA_INC $$LIBS  ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} \
                2>&1 | sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2
cuda.dependency_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
QMAKE_EXTRA_COMPILERS += cuda

1 个答案:

答案 0 :(得分:2)

我重新安装了qt并且所有工作正常(我将alpha 4.9.0和4.8.2都设置为有效)