Compiling error ubuntu 9.04 64 bits

I am using the Makefile which is provided for each example in the SDK, which references the default common.mk and I’m getting this error while trying to compile my own program.

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/…/…/…/…/lib/crt1.o: In function _start': /build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to main’
collect2: ld returned 1 exit status

I’ve maintained the structure provided in the example threadMigration, or in any example in the SDK programmes. I’ve browsed this error and from the error reports I’ve read it might be a 64-bit compiling problem. I’ve sucessfully installed Cuda 2.3 and compiled the examples provided by the SDK. The GCC is 4.3.3 version. I’ve add to the LD_LIBRARY_PATH and the other path its requirements, and as all the other SDK programmes compiled and ran sucessfully I can’t seem to point out the origin of the error. Any help is welcomed.

The linker is telling you it cannot find a main() function amongst the object files you have provided for it to link,which either means

(1) You don’t have a main(), in which case you need to write one, or
(2) You have a main, but you haven’t provided the object file containing it to the linker, in which case you need to modify your makefile

(2) is probably more likely, but only you know that for sure…

I have the same structure in the *.cu file as in the threadMigration example

//includes, system

(…)

//includes, project

#include <cutil_inline.h>

//includes, kernels

#include <threadMigration_kernel.cu>

void runTest (int argc, char** argv);

int main(int argc, char** argv)

{

runTest(argc,argv);}

void runTest(int argc,char** argv)

{

(…)

}

Only the contents in the kernel and the runTest function have been changed…

If you are using the same SDK makefile, then try building it with

make verbose=1

It won’t fix anything but it will at least show you what the compiler is doing. The original diagnosis stands - the linker isn’t finding a main().

OK this is embarrassing… It was one of those typical copy paste cases where the copy paste action must follow a sequence, I’ve tried again with new .cu, .cpp and kernel files and it has now finally compiled!

Thank you for your help and time. :thumbup:

Hello, I encounter the same problem, but I don’t want to have a main method. There is another .c file that calls a method contained in the .cu file. Is there a way to compile a .cu file without a main method ?

You can simply compile it with nvcc --compile, it will skip linking then which allows you to link the cuda code to normal c code later on, though you’ll have to pass some extra options to the linker so it wont forget the cuda libs

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