gpt4 book ai didi

c++ - 未定义的类型特征引用

转载 作者:行者123 更新时间:2023-11-28 07:22:05 25 4
gpt4 key购买 nike

我正在创建一个 CUDA/C++ 复数/函数库。特别是,我在 ComplexTypes.cuhComplexTypes.cu 文件,我有以下文件结构:

Result_Types.cuh - 类型特征文件 - 定义 result_type_promotion

/*************/
/* PROMOTION */
/*************/
template <typename, typename> struct result_type_promotion;
....
template<> struct result_type_promotion< int2_, float2_ > { typedef float2_ strongest; };
....

/*************/
/* FUNCTIONS */
/*************/

template <typename> struct result_type_root_functions;
....

Operator_Overloads.cuh

template<typename T0, typename T1> __host__ __device__ typename result_type_promotion<T0, T1>::strongest operator+(T0, T1);
....

Operator_Overloads.cu - 复数之间常见运算的重载

#include "ComplexTypes.cuh"                                     
#include "Result_Types.cuh"
#include "Operator_Overloads.cuh"
....
__host__ __device__ result_type_promotion<int2_,float2_>::strongest add(const int2_ a, const float2_ b) { result_type_promotion<int2_,float2_>::strongest c; c.c.x = a.c.x+b.c.x; c.c.y = a.c.y+b.c.y; return c; }
....
__host__ __device__ result_type_promotion<int2_,float2_>::strongest operator+(const int2_ a,const float2_ b) { return add(a,b); }

Function_Overloads.cuh

template<typename T0> typename result_type_root_functions<T0>::root_functions                   Asinh(T0);

Function_Overloads.cu - 复数上的函数重载

#include "ComplexTypes.cuh"                                     
#include "Result_Types.cuh"
#include "Operator_Overloads.cuh"

__host__ __device__ result_type_root_functions<int>::root_functions Asinh(const int a) { return asinh((float)a); }
....

以上文件,除了作为include文件处理的type traits文件外,都是在命令行使用nvcccl编译形成.lib 文件。

不幸的是,当我编译包含的主要功能时

#include "ComplexTypes.cuh"
#include "Result_Types.cuh"
#include "Operator_Overloads.cuh"
#include "Function_Overloads.cuh"

我有这种类型的链接错误

Error   247 error : Undefined reference to '_ZplIN2BB5int2_ENS0_7float2_EEN21result_type_promotionIT_T0_E9strongestES4_S5_' in '...Test.lib'

请注意:

  1. BB 命名空间中只有复杂类型 int2_float2_double2_,但我在所有定义文件中添加using namespace BB;;
  2. 当我在 Function_Overloads.cu 文件中使用 + 时出现问题;如果我不使用 +,那么不会出现问题;
  3. 我(令人惊讶地)可以在 main 函数中使用 + 而不会收到任何链接错误。

有解决这个问题的想法吗?

谢谢。

编辑

按照 billz 的建议,我通过在 Function_Overloads.cu 文件中添加显式实例化解决了这个问题,比如

__host__ __device__ result_type_promotion<int,int2_>::strongest operator+(const int a,const int2_ b);
....

最佳答案

_ZplIN2BB5int2_ENS0_7float2_EEN21result_type_promotionIT_T0_E9strongestES4_S5_

c++filt解码后变成:

result_type_promotion<BB::int2_, BB::float2_>::strongest operator+<BB::int2_, BB::float2_>(BB::int2_, BB::float2_)

这意味着你的编译器找不到函数定义,你需要在头文件中实现它。

关于c++ - 未定义的类型特征引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19266801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com