我目前正在为视频游戏开发 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 &)" (?CreateProgram@ShaderLoader@@UAEIABV?$vector@IV?$allocator@I@std@@@std@@@Z) referenced in function "public: bool __thiscall ShaderLoader::InitShaderProgram(unsigned int &)" (?InitShaderProgram@ShaderLoader@@QAE_NAAI@Z)
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 &)" (?CreateShader@ShaderLoader@@UAEIIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall ShaderLoader::InitShaderProgram(unsigned int &)" (?InitShaderProgram@ShaderLoader@@QAE_NAAI@Z)
在我的头文件中,我这样定义这三个函数:
bool InitShaderProgram(GLuint&);
GLuint CreateShader(GLenum, const std::string&);
GLuint CreateProgram(const std::vector<GLuint>&);
如果我做对了(我很可能没有做对),编译器就不会理解这些函数的来源。有谁可以帮我离开这里吗?