How to compile .c and .cu files ?

Hello,

I’m trying to compile a .cu file containing a method called by a .c file. The compilation of the two files is ok (even if I had to add a useless main method in the .cu file to compile it) but I can’t link it.

I’m using a script to do this (I had a lot of problem with the Makefile I did, I will try again to make it when I will be able to create an executable) :

[codebox]gcc -c incrementation-pu.c -o incrementation-pu.o -lstarpu

nvcc incr-kernel.cu -o incr-kernel.o -I /usr/include/cuda -I /usr/local/cuda/include -I /usr/local/cuda/lib/ -L /home_nfs/fremals/local/starpu/lib/ -L /usr/local/cuda/lib

gcc -o test incrementation-pu.o incr-kernel.o -lstarpu -L /home_nfs/fremals/local/starpu/lib/[/codebox]

The error I obtained is a really good one :

[codebox]incr-kernel.o: In function `_start’:

/build/buildd/glibc-2.9/csu/…/sysdeps/x86_64/elf/start.S:65: multiple definition of `_start’

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/…/…/…/…/lib/crt1.o:/build/buildd/glibc-2.9/csu/…/sysdeps/x86_64/elf/start.S:65: first defined here

incr-kernel.o: In function `_fini’:

/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:37: multiple definition of `_fini’

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/…/…/…/…/lib/crti.o:/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:37: first defined here

incr-kernel.o:(.rodata+0x0): multiple definition of `_IO_stdin_used’

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/…/…/…/…/lib/crt1.o:(.rodata.cst4+0x0): first defined here

incr-kernel.o: In function `__data_start’:

(.data+0x0): multiple definition of `__data_start’

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/…/…/…/…/lib/crt1.o:(.data+0x0): first defined here

incr-kernel.o: In function `main’:

(.text+0xec): multiple definition of `main’

incrementation-pu.o:incrementation-pu.c:(.text+0xe6): first defined here

incr-kernel.o: In function `_init’:

/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:25: multiple definition of `_init’

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/…/…/…/…/lib/crti.o:/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:25: first defined here

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtend.o:(.dtors+0x0): multiple definition of `DTOR_END

incr-kernel.o:(.dtors+0x8): first defined here

/usr/bin/ld: error in incr-kernel.o(.eh_frame); no .eh_frame_hdr table will be created.

collect2: ld returned 1 exit status

[/codebox]

It sees that there is two mains now, but he doesn’t want to compile if I don’t put another main in the .cu file.

To be honest, I’m completely lost (i’m searching on forums for 3-4 hours but i don’t find how to compile my files :s).

Can someone help me please ?

Thank you !!

You should pass -c (compile) to nvcc - at the moment your incr-kernel.o isn’t an object file, but a fully linked application.

Thanks a lot, I succeeded to correctly compile the code !!

Hi Eliole,

I was quite surprised to see StarPU when looking at your link flags :D) Note that you find the rules to compile the .cu files in the src/Makefile.am (in StarPU code). Speaking of which, it would really be nice if NVIDIA could provide a pkg-config file (or some home-brewed equivalent).

Sorry that you lost some time !
Cédric