CUDA int2 的重新声明无效
我有几个 .cpp 文件和几个 .h 文件。如果我使用 nvcc 而不是 g++ 编译它们,一切都很好。现在,当我开始(在 main.cpp 中)在设备上分配内存时,即
cudaMalloc( (void**)&_a, _DSIZE * sizeof(float) )
问题开始了。我尝试过将扩展名更改为.cu,但效果更糟。
我得到的错误:
mylib.h(39): error: invalid redeclaration of type name "int2" /usr/local/cuda/bin/../include/vector_types.h(402): here
mylib.h(43): error: invalid redeclaration of type name "int3" /usr/local/cuda/bin/../include/vector_types.h(406): here
mylib.h(47): error: invalid redeclaration of type name "float3" /usr/local/cuda/bin/../include/vector_types.h(434): here
显然,int2、int3、float3 等是我自己的重新声明,它们位于 mylib.h 文件中并且是全局的。
我还收到很多警告:
mylib.h(128): warning: use of a type with no linkage to declare a function
mylib.h(129): warning: use of a type with no linkage to declare a function
我做错了什么?我一直在使用 .cu 文件,但我认为扩展名并不是真的必要...
重新定义,警告关闭但仍然是一个错误:
/usr/bin/ld: FSPB_kernel_Jelen.o: bad reloc symbol index ( 0x90 >= 0x1e) 对于“.text”部分中的偏移量 0xa0100 FSPB_kernel_Jelen.o:无法读取符号:错误值 Collect2: ld 返回 1 退出状态 make: * [FSPB] 错误 1
有什么想法吗?
I have several .cpp files and a couple of .h files. If I compile them using nvcc instead of g++, everything is fine. Now, when I start (in main.cpp) to allocate memory on the device, i.e
cudaMalloc( (void**)&_a, _DSIZE * sizeof(float) )
then the problems start. I have tried to change the extension of to .cu, but it is even worst.
Errors that I get:
mylib.h(39): error: invalid redeclaration of type name "int2" /usr/local/cuda/bin/../include/vector_types.h(402): here
mylib.h(43): error: invalid redeclaration of type name "int3" /usr/local/cuda/bin/../include/vector_types.h(406): here
mylib.h(47): error: invalid redeclaration of type name "float3" /usr/local/cuda/bin/../include/vector_types.h(434): here
Obviously, int2, int3, float3 etc are my own re-declarations which are located in a mylib.h file and are global.
I also get plenty of warnings:
mylib.h(128): warning: use of a type with no linkage to declare a function
mylib.h(129): warning: use of a type with no linkage to declare a function
What am I doing wrong? I have always been working with .cu files, but I thought that it wasn't really necessary that extension...
Redefined, warnings off but still an error:
/usr/bin/ld: FSPB_kernel_Jelen.o: bad reloc symbol index (0x90 >= 0x1e) for offset 0xa0100 in section `.text'
FSPB_kernel_Jelen.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: * [FSPB] Error 1
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 CUDA 使用了这些名称,现在出现了名称冲突。选择您使用的库未采用的名称,或者更好的是,为您的代码使用命名空间。 (最好:两者都做)
Looks like CUDA uses those names, and now you have a name collision. Pick names that aren't taken by the libraries you use, or better yet, use a namespace for your code. (Best: do both)