Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:28:10+00:00 2026-06-11T01:28:10+00:00

I have been trying for days to get a Qt project file running on

  • 0

I have been trying for days to get a Qt project file running on a 32-bit Windows 7 system, in which I want/need to include Cuda code. This combination of things is either so simple that no one ever bothered to put an example online, or so difficult that nobody ever succeeded, it seems. Whatever way, the only helpful forum threads I found were the same issue on Linux or Mac, or with Visual Studio on a Windows.
All of these give all sorts of different errors, however, whether due to linking or clashing libraries, or spaces in file names or non-existing folders in the Windows version of the Cuda SDK.
Is there someone who has a clear .pro file to offer that does the trick?

I am aiming to compile a simple programme with ordinary C++ code in Qt style, with Qt 4.8 libraries, which reference several Cuda modules in .cu files. Something of the form:

TestCUDA \
    TestCUDA.pro
    main.cpp
    test.cu
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:28:11+00:00Added an answer on June 11, 2026 at 1:28 am

    So I finally managed to assemble a .pro file that works on my and probably on all Windows systems. The following is an easy test programme that should probably do the trick. The following is a small project file plus test programme that works at least on my system.

    The file system looks as follows:

    TestCUDA \
        TestCUDA.pro
        main.cpp
        vectorAddition.cu
    

    The project file reads:

    TARGET = TestCUDA
    
    # Define output directories
    DESTDIR = release
    OBJECTS_DIR = release/obj
    CUDA_OBJECTS_DIR = release/cuda
    
    # Source files
    SOURCES += src/main.cpp
    
    # This makes the .cu files appear in your project
    OTHER_FILES +=  vectorAddition.cu
    
    # CUDA settings <-- may change depending on your system
    CUDA_SOURCES += src/cuda/vectorAddition.cu
    CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.2/C"   # Path to cuda SDK install
    CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2"            # Path to cuda toolkit install
    SYSTEM_NAME = Win32         # Depending on your system either 'Win32', 'x64', or 'Win64'
    SYSTEM_TYPE = 32            # '32' or '64', depending on your system
    CUDA_ARCH = sm_11           # 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
    
    # 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 = $$CUDA_OBJECTS_DIR/${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} ${QMAKE_FILE_NAME}
        cuda_d.dependency_type = TYPE_C
        QMAKE_EXTRA_COMPILERS += cuda_d
    }
    else {
        # Release mode
        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 $$LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
        cuda.dependency_type = TYPE_C
        QMAKE_EXTRA_COMPILERS += cuda
    }
    

    Note the QMAKE_LFLAGS_RELEASE = /NODEFAULTLIB:msvcrt.lib: it took me a long time to figure out, but this library seems to clash with other things in Cuda, which produces strange linking warnings and errors. If someone has an explanation for this, and potentially a prettier way to get around this, I’d like to hear it.

    Also, since Windows file paths often include spaces (and NVIDIA’s SDK by default does so too), it is necessary to artificially add quotation marks around the include paths. Again, if someone knows a more elegant way of solving this problem, I’d be interested to know.

    The main.cpp file looks like this:

    #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;
    }
    

    The Cuda file vectorAddition.cu, which describes a simple vector addition, look like this:

    #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);
    }
    

    If you get this to work, then more complicated examples are self-evident, I think.

    Edit (24-1-2013): I added the QMAKE_LFLAGS_DEBUG = /NODEFAULTLIB:msvcrtd.lib and the CONFIG(debug) with the extra D_DEBUG flag, such that it also compiles in debug mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a few days now, I have been trying to get my Java project
I have been trying for several days to get the proper formatting for what
I have been trying to days now to get this website completed ... however,
I have been trying for 4 days to get app-engine and grails working together
I have been trying to get a2billing to work for the past 4 days
I have been trying to get this to work for about three solid days
So I have been trying to get this to work 2 days and I
For the past couple of days, I have been trying to get GWT to
I have been trying for 2 days now to get a UIPickerView to show
I have been trying for what seems like two days now to get my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.