我目前正在为视频游戏开发一个OpenGL框架。该框架包含加载着色器的特定程序。在课堂上说,程序的我有三个功能:另一个“未解析的外部符号”错误
InitShaderProgram(...);
CreateShader(...);
CreateProgram(...);
的InitShaderProgram调用CreateShader和CreateProgram以这样的方式:
bool ShaderLoader::InitShaderProgram(GLuint &Program)
{
std::vector<GLuint> ShaderList;
ShaderList.push_back(ShaderLoader::CreateShader(GL_VERTEX_SHADER, VertexShader));
ShaderList.push_back(ShaderLoader::CreateShader(GL_FRAGMENT_SHADER, FragmentShader));
Program = ShaderLoader::CreateProgram(ShaderList);
std::for_each(ShaderList.begin(), ShaderList.end(), glDeleteShader);
return GL_TRUE;
}
然而,每当我试图编译这段代码,它给了我两个“解析的外部符号”错误:
Error 4 error LNK2019: unresolved external symbol "public: virtual unsigned int __thiscall ShaderLoader::CreateProgram(class std::vector<unsigned int,class std::allocator<unsigned int> > const &)" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@@Z) referenced in function "public: bool __thiscall ShaderLoader::InitShaderProgram(unsigned int &)" ([email protected]@@[email protected])
Error 3 error LNK2019: unresolved external symbol "public: virtual unsigned int __thiscall ShaderLoader::CreateShader(unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: bool __thiscall ShaderLoader::InitShaderProgram(unsigned int &)" ([email protected]@@[email protected])
在我的头文件中,我定义这三个功能,例如:
bool InitShaderProgram(GLuint&);
GLuint CreateShader(GLenum, const std::string&);
GLuint CreateProgram(const std::vector<GLuint>&);
如果我得到这个权利(我很可能不),编译器不明白这些函数来自哪里。有人可以帮我从这里出去吗?
你是如何编译的? – 2013-03-21 16:11:14
就像关于同一主题的所有其他问题一样:您没有链接到符号的定义。找出他们居住的地方,把他们联系起来,完成。 – PlasmaHH 2013-03-21 16:13:23
这些函数与InitShaderProgram()函数存在于同一个类中,不会使它们默认链接? – valtari 2013-03-21 16:17:17