0
我一直在嘗試編譯一組C和CUDA代碼。問題在於我編寫文件時編譯的鏈接階段。我做了一個包裝函數在主機上執行,以便在設備上分配內存,將數據複製到它並運行內核代碼。此外,包裝代碼與內核代碼包含在同一文件中。包裝。下面是代碼是如何調用該函數:將錯誤與CUDA和GCC鏈接
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "LAMMPS.h"
...
main(int argc, char **argv)
{
...
tortuosityTotal = gradient(nbAtoms, topAtoms, bottomAtoms, nTop, nBottom, allConnections, atomlist, ysize);
這裏是我做出的頭文件「LAMMPS.h」的功能定義:
float gradient(unsigned short nbAtoms, unsigned short *topAtoms,unsigned short
*bottomAtoms, unsigned short nTop, unsigned short nBottom, struct connection
**allConnections,struct atoms *atomlist, double *ysize);
這裏是我使用生成文件:
all: tortGPU
tortGPU: gradient_kernel.o buildNeighborList.o dumpRead.o tortuosityGPU.c
nvcc tortuosityGPU.c buildNeighborList.o dumpRead.o gradient_kernel.o -lm -o tortGPU
buildNeighborList.o: dumpRead.o buildNeighborList.c
gcc -c buildNeighborList.c
dumpRead.o: dumpRead.c
gcc -c dumpRead.c
gradient_kernel.o:
nvcc -c gradient_kernel.cu -arch=sm_20
clean: rm -rf *.o program
最後,編譯步驟做工精細,但是當我去他們都連接在一起(與tortGPU最後一步,我得到了以下錯誤消息:
/tmp/tmpxft_000068c7_00000000-1_tortuosityGPU.o: In function `main':
tortuosityGPU.c:(.text+0x520): undefined reference to `gradient'
collect2: ld returned 1 exit status
make: *** [tortGPU] Error 1
我試着用gcc加-L,並得到完全相同的錯誤代碼。 謝謝!
謝謝!我會嘗試... – user1591385 2012-08-13 15:15:58