热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

关于c:CUDA5.5nvlinkundefinedreference(inheritance)

CUDA5.5nvlinkundefinedreference(inheritance)


CUDA 5.5 nvlink undefined reference (inheritance)


我一直在研究我的 GPU-raytracer 实现,但由于我是 CUDA 的新手,我在编译和链接单独的 .cu 文件时遇到了一些问题。

我的 2 个课程:Shader 和 Lambert。 Lambert 继承了 Shader 接口。当我编译时,我收到以下错误:










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


Error 4 error MSB3721: The command""G:\\Development\\CUDA Toolkit\\CUDA Toolkit v5.5\\bin\

vcc.exe"

-dlink -o"
Debug\\CUDA RayTracer.device-link.obj" -Xcompiler"/EHsc /W3 /nologo /Od /Zi /RTC1  
/MDd " -L"P:\\My Projects\\CUDA Ray-Tracer\\CUDA RayTracer\\ThirdParty\\SDL\\lib\\x86" -L"P:\\My

Projects\\CUDA Ray-Tracer\\CUDA RayTracer\\CUDA RayTracer\\\\..\\ThirdParty" -L"G:\\Development\\CUDA

Toolkit\\CUDA Toolkit v5.5\\lib\\Win32" cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib

comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

SDL.lib SDLmain.lib  -gencode=arch=compute_30,code=sm_30 -G --machine 32 Debug\\Camera.cu.obj

Debug\\IShader.cu.obj Debug\\Lambert.cu.obj Debug\\Matrix.cu.obj Debug\\Plane.cu.obj

Debug\\sdl.cu.obj Debug\\cuda_renderer.cu.obj"
exited with code -1.  
C:\\Program Files(x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\V110\\BuildCustomizations\\CUDA 5.5.targets  668

1>nvlink : error : Undefined reference to '_ZN6ShaderD1Ev' in 'Debug/IShader.cu.obj'
1>nvlink : error : Undefined reference to '_ZN6ShaderD0Ev' in 'Debug/IShader.cu.obj'
1>nvlink : error : Undefined reference to '_ZN6ShaderD2Ev' in 'Debug/Lambert.cu.obj'



我不知道 \\'_ZN6ShaderD1Ev\\' 是什么意思,我认为在我的实现中一切都是正确的(C 明智的,不确定 CUDA 对此有何看法)。据我所知,CUDA 5.5 支持虚函数和继承。

我已经安装了 CUDA 5.5 Toolkit,并在我的 Visual Studio 2012 中启用了"生成可重定位设备代码"。我还设置了 \\'compute_30,sm_30\\',以便使用 \\'operator new\\ '(我的显卡可以做到 - GTX670MX)。我的项目仅包含 .cu 和 .cuh 文件。

我的源代码:










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78



//IShader.cuh
#ifndef I_SHADER_H
#define I_SHADER_H

#include"Vector3D.cuh"
#include"Color.cuh"
#include"IGeometry.cuh"

__device__ extern Vector cameraPos;

__device__ extern Vector lightPos;

__device__ extern Color lightColor;

__device__ extern float lightPower;

__device__ extern Color ambientLight;

class Shader
{
protected:

     Color _color;

public:

    __device__ Shader(const Color& color);

    __device__ virtual ~Shader();

    __device__ virtual Color shade(Ray ray, const IntersectionData& data) = 0;
};

#endif

//IShader.cu
#include"IShader.cuh"

__device__ Shader::Shader(const Color& color)
{

   this->_color = color;
}

// Lambert.cuh
#ifndef LAMBERT_H
#define LAMBERT_H

#include"IShader.cuh"

class Lambert : public Shader
{
public:

    __device__ Lambert(const Color& diffuseColor);

    __device__ Color shade(Ray ray, const IntersectionData& data);
};

#endif

//Lambert.cu
#include"Lambert.cuh"

Vector cameraPos;

Vector lightPos;

Color lightColor;
float lightPower;

Color ambientLight;

__device__ Lambert::Lambert(const Color& diffuseColor)

    : Shader(diffuseColor)
{
}

__device__ Color Lambert::shade(Ray ray, const IntersectionData& data)
{

    Color result = _color;

    result = result * lightColor * lightPower / (data.p - lightPos).lengthSqr();

    Vector lightDir = lightPos - data.p;

    lightDir.normalize();

    double cosTheta = dot(lightDir, data.normal);

    result = result * cosTheta;

    return result;
}



如果你需要更多代码,我可以给你 github repo 的链接。

我希望你能帮助我。

提前致谢!



相关讨论




  • 尝试使用 c filtjs 在线拆解器。 _ZN6ShaderD1Ev 表示 Shader::~Shader()


  • 天哪,真是一个愚蠢的错误,这对我帮助很大。确实是我没有定义的析构函数。非常感谢你 !


  • @JackOLantern 如果你写了一个答案,我会支持它






C 允许以相同标识符命名的不同实体(例如函数)属于不同的命名空间。为了唯一地解析名称,编译器使用名称修饰,也就是说,它在所涉及的实体的名称中编码附加信息。这就是 nvlink 指代这个"晦涩"实体 _ZN6ShaderD1Ev 的原因。为了恢复一个更易于理解的名称,需要进行拆解操作。

虽然有拆解软件,但我经常使用在线拆解器

c 过滤器

使用这个页面,你可以发现










1


_ZN6ShaderD1Ev


其实就是










1


Shader::~Shader()


反过来,这表明您没有为 Shader() 类定义析构函数。






推荐阅读
author-avatar
兰雪儿MM_840
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有