Linking problem mingw-gcc with cuda withOUT Visual Studio

cuda_problem_example.zip (2.06 KB)

Hi, I am a new to cuda and I would like to create a statical cuda library for the gpu-part of my program, and then I would like to link this with c/c++ objects generated with qt or mingw-gcc/g++ later.

I created a minimal representation of my problem and attached here.

I have win7 x64, cuda, mingw installed

I have visual studio as well, but i dont want to use that, because I am planning to do this with Qt later.

As you can see in the attached example (or below), I would like to create a statical library for the cuda-part of my application. This can be done with the MakeStatlib.bat, which’s first call is to setup the environment for the visual compiler (I read this in the nvcc manual)

Then, I would like to create a runnable app, which would call the call() function which takes place in cudalib.lib

I can successfully create cudalib.lib, but unfortunately cannot link it together with main.o, the linker says:

gcc main.o cudalib.lib -o app

main.o:main.c:(.text+0xc): undefined reference to ‘call’

collect2: ld returned 1 exit status

The content of the uploaded example:

files:

kernel.cu

caller.cu

kernel.h

caller.h

main.c

MakeStatlib

MakeStatlib.bat

MakeRunnable

MakeRunnable.bat

in kernel.cu:

__global__ void calculateKernel()

{

}

in caller.cu:

#include <cuda.h> /* dim3 */

#include "kernel.h" /* calculateKernel() */

void call()

{

 dim3 dimBlock(1,1);

 dim3 dimGrid(1,1);

 calculateKernel<<< dimGrid, dimBlock >>>();

}

in kernel.h:

#ifndef KERNEL_H

#define KERNEL_H

__global__ void calculateKernel();

#endif /* KERNEL_H */

in caller.h:

#ifndef CALLER_H

#define CALLER_H

void call();

#endif /* CALLER_H */

in main.c:

#include "caller.h" /* call() */

int main()

{

 call();

 return 0;

}

in MakeStatlib:

cudalib.lib: kernel.obj caller.obj

 nvcc -lib kernel.obj caller.obj -o cudalib.lib

kernel.obj: kernel.cu kernel.h

 nvcc -c kernel.cu -o kernel.obj

caller.obj: caller.cu caller.h kernel.h

 nvcc -c caller.cu -o caller.obj

in MakeStatlib.bat:

call "c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"

mingw32-make -f MakeStatlib

in MakeRunnable:

app: main.o cudalib.lib

 gcc main.o cudalib.lib -o app

main.o: main.c caller.h

 gcc -c main.c -o main.o

cudalib.lib: kernel.cu caller.h caller.cu

 MakeStatlib.bat

in MakeRunnable.bat:

mingw32-make -f MakeRunnable

PAUSE

Any help appreciated.

My email is kottalovag[TA]gmail[TOD]com, if easier

David