3

I'm trying to compile a CUDA program in Linux and I get the following linker error:

/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

This is my Makefile:

mtrand.o : mtrand/mtrand.cpp
    nvcc -I"./mtrand" -O2 -c mtrand/mtrand.cpp

CUDAMCMLrng.o : CUDAMCMLrng.cu
    nvcc --use_fast_math -O2 -c CUDAMCMLrng.cu

kernel.o : CUDAMCMLrng.o kernel.cu
    nvcc --use_fast_math -O2 -c kernel.cu

main.o : mtrand.o CUDAMCMLrng.o kernel.o main.cu
    nvcc --use_fast_math -O2 -Xcompiler "-fopenmp -Wall" -c main.cu

lab : main.o mtrand.o CUDAMCMLrng.o kernel.o
    nvcc -lgomp -o lab main.o mtrand.o CUDAMCMLrng.o kernel.o

The main function is in the main.cu file but for some reason the linker is not seeing it. Could anyone please tell me what am I doing wrong?

Thanks!

Kevin
  • 53,822
  • 15
  • 101
  • 132
santisan
  • 149
  • 1
  • 11

1 Answers1

1

I recommend doing the final linking with g++ rather than nvcc. If you only have .o files and libraries as input to the link line, I see no reason to use nvcc.

harrism
  • 26,505
  • 2
  • 57
  • 88