问题
I have host files (say h_A.cpp, etc) which can be compiled by host compiler (g++), device files (say d_A.cu, etc) to be compiled by device compiler (nvcc) and host-device files i.e., host functions, kernel call, etc (say h_d_A.cu) to be compiled by device compiler (nvcc).
Device side compilation
nvcc -arch=sm_20 -dc d_A.cu -o d_A.o $(INCLUDES)
/* -dc since the file may call / have relocatable device functions */
Host side compilation
g++ -c h_A.cpp -o h_A.o $(INCLUDES, FLAGS)
Device Linkage as suggested here
nvcc -arch=sm_20 -dlink d_A.o -o link.o
/* Linkage due to relocatable device functions */
I am using Makefile for the project. Now, the query i have is, how do i form the final executable? I have tried,
1. g++ h_A.o link.o –L<path> -lcudart
Error: relocation 0 has invalid symbol index 10
2. g++ h_A.o link.o –lcudadevrt –L<path> –lcudart
Error: undefined reference to phase2(int*, int) //where phase2 is my __global__ kernel.
回答1:
Sorry, Found out the problem i missed to include device objects while forming the final executable.
corrected syntax.
g++ h_A.o d_A.o link.o –L<path> -lcudart
来源:https://stackoverflow.com/questions/20966846/cuda-compilation-and-linking