Linking problem mingw-gcc with cuda withOUT Visual Studio (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:










__global__ void calculateKernel()




#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()



 return 0;


in MakeStatlib:

cudalib.lib: kernel.obj caller.obj

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

kernel.obj: kernel.h

 nvcc -c -o kernel.obj

caller.obj: caller.h kernel.h

 nvcc -c -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: caller.h


in MakeRunnable.bat:

mingw32-make -f MakeRunnable


Any help appreciated.

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