【发布时间】:2013-06-12 23:18:07
【问题描述】:
我正在研究 DNA 片段组装程序。纯 CPU 版本是使用 GCC 用 C 语言构建的,我正在尝试使用 NVCC 构建 GPU 版本。
这是生成文件
all : clean FragmentAssembly.exe
FragmentAssembly.exe : Common.o Fragment.o ILS.o Consensus.o main.o
nvcc -pg -o FragmentAssembly.exe Common.o Fragment.o ILS.o Consensus.o main.o
Common.o : Common.cu
nvcc -pg -o Common.o -c Common.cu
Fragment.o : Fragment.cu
nvcc -pg -o Fragment.o -c Fragment.cu
ILS.o : ILS.cu
nvcc -pg -o ILS.o -c ILS.cu
Consensus.o : Consensus.cu
nvcc -pg -o Consensus.o -c Consensus.cu
main.o : main.cu
nvcc -pg -o main.o -c main.cu
clean :
rm -f *.exe *.o
正如所见,原来的 .c 文件变成了 .cu 文件,供 nvcc 正确编译。
除了main.cu之外,所有的cu文件都包含它们对应的文件(Common.h for Common.cu等)。
ILS.h 包含全局变量p_instanceFragments 和p_instanceLength 的定义
问题是在编译 NVCC 时,由于未知原因,我收到以下错误:
Consensus.o:(.bss+0x0): multiple definition of `p_instanceFragments'
ILS.o:(.bss+0x0): first defined here
Consensus.o:(.bss+0x8): multiple definition of `p_instanceLength'
ILS.o:(.bss+0x8): first defined here
没有真正的多重定义,因为使用 GCC 正确构建了相同的代码。看起来ILS.h 被两次包含在 nvcc 中,分别是 ILS.cu 和 Consensus.cu。这也是不可能的,因为我已经用 #ifndef .. #define .. #endif 语句包装了我的所有头文件,以避免多次包含和无限包含循环。
也许与 makefile 命令有关?还是我应该使用 gcc 进行链接?能告诉我怎么处理吗?
问候,
【问题讨论】:
-
没有任何代码(尤其是头文件中 p_instanceFragments 的定义),或多或少都无法判断出什么问题……只是提示:有没有可能在
ILS.h你用过int p_instanceFragments;之类的东西吗? (当然你可能有一个更复杂的类型,而不是int)。这实际上是一个链接器问题。我猜您需要在ILS.h中使用extern int p_instanceFragments;,然后在Consensus.cu或 中使用ILS.cu,您需要声明int p_InstanceFragments;。当然,所有这些都是完全没有代码的猜测工作...... -
解决了这个问题,谢谢:)
标签: c hyperlink makefile nvcc multiple-definition-error