简体   繁体   English

CUDA链接器错误:未定义对主引用

[英]CUDA linker error: undefined reference to main

I'm trying to compile a CUDA program in Linux and I get the following linker error: 我正在尝试在Linux中编译CUDA程序,并且出现以下链接器错误:

/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: 这是我的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. main功能位于main.cu文件中,但由于某些原因,链接器看不到它。 Could anyone please tell me what am I doing wrong? 谁能告诉我我在做什么错?

Thanks! 谢谢!

I recommend doing the final linking with g++ rather than nvcc. 我建议使用g ++而不是nvcc进行最终链接。 If you only have .o files and libraries as input to the link line, I see no reason to use nvcc. 如果只有.o文件和库作为链接行的输入,我认为没有理由使用nvcc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM