5

I've seen many old tries to combine QtCreator with CUDA, but they all don't work anymore.

So I'm starting this topic so that there could be a new reference for everyone.

First, I tried to compile the code like the book mentions, with the following command:

nvcc seqCuda.cu -o seqCuda

But I got the error: invalid redecleration of type name "size_t".

The only thing I was able to do was compiling this sample code from the book "CUDA Application Design and Development" using Visual Studio 2010; however, VS2010 isn't the environment I wanna use. So I went to log files and took the execution command it uses, and it's the following:

nvcc -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\include"    --keep-dir "Release" -maxrregcount=0  --machine 32 --compile      -Xcompiler "/EHsc /nologo /Od /Zi  /MD " -o "Release\main.cu.obj" "C:\Users\Sam\Documents\Visual Studio 2010\Projects\CUDA_TestVS2010\CUDA_TestVS2010\main.cu"

This command creates an object file. I could execute it for the sample code from seqCuda.cu successfully, but I don't know how to go from the object file to the executable. I want to do that in Qt using a qmake file.

Could anyone please tell me what are the important parts of this compiling command and how I can do it the merge it the right way in a qmake file?

Now my problem is, I tried to disassemble this command and rewrite it with qmake, and yes I was stabbing in the dark, and couldn't achieve any satisfying result. The following is my "try" to do that in qmake. If you could replace any of the commands in the following qmake with environment variables, I'd be thankful, especially the VC2010 bin dir.

win32 {
    INCLUDEPATH += $(CUDA_INC_PATH)
    QMAKE_LIBDIR += $(CUDA_LIB_PATH)
    ARCFLAGS = -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env
    VSVERSIONFLAGS = --cl-version 2010
    VSDIRFLAG = -ccbin "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin"
    OTHERFLAGS = -maxrregcount=0  --machine 32 --compile     
    -Xcompiler "/EHsc /nologo /Od /Zi  /MD "
    LIBS += -lcudart

    cuda.output = ./${QMAKE_FILE_BASE}_cuda.obj
    cuda.commands = $(CUDA_BIN_PATH)/nvcc.exe $$ARCFLAGS $$VSVERSIONFLAGS $$VSDIRFLAG -  
    I$(CUDA_INC_DIR)     $$OTHERFLAGS
}

CUDA_SOURCES += seqCuda.cu
cuda.input = CUDA_SOURCES
QMAKE_EXTRA_COMPILERS += cuda
  • Did you tried 'http://stackoverflow.com/questions/7800093/qt-cuda-setting-qmake-pro-file' – pQB Jun 08 '12 at 16:10
  • @pQB yes actually. I tried modifying that, but failed... What I ended with eventually is what I provided in the question. –  Jun 08 '12 at 22:11
  • I don't know anything about qmake, but to go from object files to executables, you just need to use your system compiler / linker to link the files together with any required libraries. e.g. with the MSVC linker, `link a.o b.o c.o cudart.lib /LIBPATH /OUT myProgram.exe`. Not sure if this is helpful or not... – harrism Jun 19 '12 at 03:54
  • 1
    What is the question, exactly? You need to ask a specific question. Do you get error messages? As for the first problem of compiling with nvcc and getting a redefinition of size_t, it sounds like you are redefining size_t, but since you didn't include any code, I can't be sure. I voted to close this because it is not a real question. – harrism Aug 31 '12 at 02:29
  • 1
    Your code seems fine, it would be helpful to know why this doesn't work, as you code looks like perfectly legal qmake code. In the following thread, you'll find a complete (small) Qt project with CUDA, much like your own, which may be of help: http://stackoverflow.com/questions/12266264/compiling-cuda-code-in-qt-creator-on-windows – Yellow May 02 '13 at 17:02

0 Answers0