Error include cudalib in qtcreator windows

Hello,
I work on windows with qtcreator.
I found a example on internet to use cudalib on windows with a simple vectorADD example.
I compile the example and I get that error:

vectorAddition_cuda.o ../CudaWindows/vectorAddition.cu
vectorAddition.cu
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: ___cudaRegisterFatBinary@4 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: ___cudaUnregisterFatBinary@4 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: ___cudaRegisterFunction@40 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: _cudaSetupArgument@12 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: _cudaMalloc@8 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: _cudaFree@4 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: _cudaMemcpy@16 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: _cudaLaunch@4 already defined in cudart.lib(cudart32_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: _cudaConfigureCall@32 already defined in cudart.lib(cudart32_80.dll)
   Creating library vectorAddition_cuda.lib and object vectorAddition_cuda.exp
LINK : fatal error LNK1561: entry point must be defined
Makefile.Release:106: recipe for target 'vectorAddition_cuda.o' failed
mingw32-make[1]: Leaving directory 'C:/Users/xx/Desktop/Developpement/Cuda/build-CudaWindows-Desktop_Qt_5_7_0_MinGW_32bit-Release'
mingw32-make[1]: *** [vectorAddition_cuda.o] Error 2
Makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2
11:27:43: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project CudaWindows (kit: Desktop Qt 5.7.0 MinGW 32bit)
When executing step "Make"
11:27:43: Elapsed time: 00:02.

I don’t understand the error code.

Are you using MSVC to build the code or MINGW32? CUDA supports only Microsoft Visual C as the host compiler on Windows.

The error message “entry point must be defined” typically means an executable (.exe) is being built, but the compiler cannot find main(). If you are building a library (.dll or .lib), you obviously don’t need an entry point.

In general it will be difficult for others to assist with random, unknown, code you grabbed from the internet. Assistance with debugging typically requires access to the source code and the exact build instructions. Since nobody wants to deal with large codes in this context, the typical requirement is for an MCVE (see this link for an explanation: http://stackoverflow.com/help/mcve).

Here is more information about my example projec. Here is my .pro file:

TARGET = TestCUDA

# Define output directories
DESTDIR = release
OBJECTS_DIR = release/obj
CUDA_OBJECTS_DIR = release/cuda

# Source files
SOURCES += main.cpp

# This makes the .cu files appear in your project

# CUDA settings <-- may change depending on your system
CUDA_SOURCES += vectorAddition.cu
CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/CUDA Samples/v8.0"   # Path to cuda SDK install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"            # Path to cuda toolkit install
SYSTEM_NAME = Win64         # Depending on your system either 'Win32', 'x64', or 'Win64'
SYSTEM_TYPE = 64            # '32' or '64', depending on your system
CUDA_ARCH = compute_52           # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS = --use_fast_math

# include paths
INCLUDEPATH += $$CUDA_DIR/include \
               $$CUDA_SDK/common/inc/ \
               $$CUDA_SDK/../shared/inc/

# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME \
                $$CUDA_SDK/common/lib/$$SYSTEM_NAME \
                $$CUDA_SDK/../shared/lib/$$SYSTEM_NAME
# Add the necessary libraries
LIBS += -lcuda -lcudart
LIBS += -L\"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.14393.0/um/x86\"

#INCLUDEPATH +=  "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/"
INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10150.0/ucrt"
#INCLUDEPATH += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.14393.0/um/x86"



# The following library conflicts with something in Cuda
#QMAKE_LFLAGS_RELEASE = /NODEFAULTLIB:msvcrt.lib
#QMAKE_LFLAGS_DEBUG   = /NODEFAULTLIB:msvcrtd.lib

# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')

# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
    # Debug mode
    cuda_d.input = CUDA_SOURCES
    cuda_d.output = ${QMAKE_FILE_BASE}_cuda.o
    cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} vectorAddition.cu
    cuda_d.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
    # Release mode
    cuda.input = CUDA_SOURCES
    cuda.output = ${QMAKE_FILE_BASE}_cuda.o
    cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS  --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -o ${QMAKE_FILE_OUT} ../CudaWindows/vectorAddition.cu
    cuda.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda
}

My main file:

#include <cuda.h>
#include <builtin_types.h>
#include <drvapi_error_string.h>

#include <QtCore/QCoreApplication>

#include <QDebug>

// Forward declare the function in the .cu file
void vectorAddition(const float* a, const float* b, float* c, int n);

void printArray(const float* a, const unsigned int n) {
    QString s = "(";
    unsigned int ii;
    for (ii = 0; ii < n - 1; ++ii)
        s.append(QString::number(a[ii])).append(", ");
    s.append(QString::number(a[ii])).append(")");

    qDebug() << s;
}

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

    int deviceCount = 0;
    int cudaDevice = 0;
    char cudaDeviceName [100];

    unsigned int N = 50;
    float *a, *b, *c;

    cuInit(0);
    cuDeviceGetCount(&deviceCount);
    cuDeviceGet(&cudaDevice, 0);
    cuDeviceGetName(cudaDeviceName, 100, cudaDevice);
    qDebug() << "Number of devices: " << deviceCount;
    qDebug() << "Device name:" << cudaDeviceName;

    a = new float [N];    b = new float [N];    c = new float [N];
    for (unsigned int ii = 0; ii < N; ++ii) {
        a[ii] = qrand();
        b[ii] = qrand();
    }

    // This is the function call in which the kernel is called
    vectorAddition(a, b, c, N);

//    qDebug() << "input a:"; printArray(a, N);
//    qDebug() << "input b:"; printArray(b, N);
//    qDebug() << "output c:"; printArray(c, N);

    if (a) delete a;
    if (b) delete b;
    if (c) delete c;
}

And my vectorAddition.cu :

#include <cuda.h>
#include <builtin_types.h>

extern "C"
__global__ void vectorAdditionCUDA(const float* a, const float* b, float* c, int n)
{
    int ii = blockDim.x * blockIdx.x + threadIdx.x;
    if (ii < n)
        c[ii] = a[ii] + b[ii];
}

void vectorAddition(const float* a, const float* b, float* c, int n) {
    float *a_cuda, *b_cuda, *c_cuda;
    unsigned int nBytes = sizeof(float) * n;
    int threadsPerBlock = 256;
    int blocksPerGrid   = (n + threadsPerBlock - 1) / threadsPerBlock;

    // allocate and copy memory into the device
    cudaMalloc((void **)& a_cuda, nBytes);
    cudaMalloc((void **)& b_cuda, nBytes);
    cudaMalloc((void **)& c_cuda, nBytes);
    cudaMemcpy(a_cuda, a, nBytes, cudaMemcpyHostToDevice);
    cudaMemcpy(b_cuda, b, nBytes, cudaMemcpyHostToDevice);

    vectorAdditionCUDA<<<blocksPerGrid, threadsPerBlock>>>(a_cuda, b_cuda, c_cuda, n);

    // load the answer back into the host
    cudaMemcpy(c, c_cuda, nBytes, cudaMemcpyDeviceToHost);

    cudaFree(a_cuda);
    cudaFree(b_cuda);
    cudaFree(c_cuda);
}

I try have that error:

cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: __cudaUnregisterFatBinary already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: __cudaRegisterFunction already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaSetupArgument already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaMalloc already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaFree already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaMemcpy already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaLaunch already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaConfigureCall already defined in cudart.lib(cudart64_80.dll)
   Creating library vectorAddition_cuda.lib and object vectorAddition_cuda.exp
LINK : fatal error LNK1561: entry point must be defined

I tried to modify links but I try have that error.

Hello,

I am still stuck with that message:

C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Release
	C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/bin/nvcc.exe --use_fast_math -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/include" -I"C:/ProgramData/NVIDIA Corporation/CUDA Samples/v8.0/common/inc/" -I"C:/ProgramData/NVIDIA Corporation/CUDA Samples/v8.0/../shared/inc/" -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.10150.0/ucrt" -lcuda -lcudart -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.14393.0/um/x86" --machine 64 -arch=compute_52 -o vectorAddition_cuda.o ../CudaWindows/vectorAddition.cu
vectorAddition.cu
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: __cudaRegisterFatBinary already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: __cudaUnregisterFatBinary already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(cuda_runtime_api.obj) : error LNK2005: __cudaRegisterFunction already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaSetupArgument already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaMalloc already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaFree already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaMemcpy already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaLaunch already defined in cudart.lib(cudart64_80.dll)
cudart_static.lib(generated_cuda_runtime_api.obj) : error LNK2005: cudaConfigureCall already defined in cudart.lib(cudart64_80.dll)
   Creating library vectorAddition_cuda.lib and object vectorAddition_cuda.exp
LINK : fatal error LNK1561: entry point must be defined

Where could I get a simple Cuda example on Qtcreator?

Edit : I use a MSVC2015 64bit kit.