【问题标题】:CUDA invalid redeclaration of int2CUDA 无效重新声明 int2
【发布时间】:2011-06-17 15:38:06
【问题描述】:

我有几个 .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: '.text' 部分中偏移量 0xa0100 的错误重定位符号索引 (0x90 >= 0x1e) FSPB_kernel_Jelen.o:无法读取符号:错误值 collect2: ld 返回 1 个退出状态 make: * [FSPB] 错误 1

有什么想法吗?

【问题讨论】:

  • 请出示int2等的声明/定义等
  • typedef struct { int x, y; }int2; typedef struct { int x, y, z; }int3;

标签: c++ porting cuda


【解决方案1】:

显然,int2、int3、float3 等是我自己的重新声明,它们位于 mylib.h 文件中并且是全局的。

看起来 CUDA 使用了这些名称,现在您遇到了名称冲突。选择您使用的库没有使用的名称,或者更好的是,为您的代码使用命名空间。 (最好:两者都做)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多