C++ 无法从opengl红皮书编译示例
所以我有这个代码:C++ 无法从opengl红皮书编译示例,c++,opengl,linker,C++,Opengl,Linker,所以我有这个代码: #include <iostream> #include <vgl.h> #include <LoadShaders.h> using std::cerr; using std::endl; enum VAO_IDs { Triangles, NumVAOs }; enum Buffer_IDs { ArrayBuffer, NumBuffers }; enum Attrib_IDs { vPosition = 0 }; GLuint V
#include <iostream>
#include <vgl.h>
#include <LoadShaders.h>
using std::cerr;
using std::endl;
enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
//---------------------------------------------------------------------
//
// init
//
void
init(void)
{
glGenVertexArrays(NumVAOs, VAOs);
glBindVertexArray(VAOs[Triangles]);
GLfloat vertices[NumVertices][2] = {
{ -0.90, -0.90 }, // Triangle 1
{ 0.85, -0.90 },
{ -0.90, 0.85 },
{ 0.90, -0.85 }, // Triangle 2
{ 0.90, 0.90 },
{ -0.85, 0.90 }
};
glGenBuffers(NumBuffers, Buffers);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, "triangles.vert" },
{ GL_FRAGMENT_SHADER, "triangles.frag" },
{ GL_NONE, NULL }
};
GLuint program = LoadShaders(shaders);
glUseProgram(program);
glVertexAttribPointer(vPosition, 2, GL_FLOAT,
GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vPosition);
}
//---------------------------------------------------------------------
//
// display
//
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAOs[Triangles]);
glDrawArrays(GL_TRIANGLES, 0, NumVertices);
glFlush();
}
//---------------------------------------------------------------------
//
// main
//
int
main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512, 512);
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow(argv[0]);
if (glewInit()) {
cerr << "Unable to initialize GLEW ... exiting" << endl;
exit(EXIT_FAILURE);
}
init();
glutDisplayFunc(display);
glutMainLoop();
}
我遵循了@Mario在这里所说的:
我的链接器上有以下附加依赖项:
当我添加glut32.lib时,我得到一个无法打开的错误,因此我下载了它并将其添加到C:\Program Files(x86)\Microsoft SDK\Windows\v7.0A\lib,但我仍然得到相同的错误
示例的文件以及所有库和内容可在此处找到:
编辑:我的代码生成运行库是:多线程DLL(/MD)您使用的GLUT版本是根据运行库的不同版本/配置构建的。我建议您安装(原始GLUT早已过时),并确保您使用与应用程序相同的配置构建freeglut。您使用的GLUT版本是根据运行库的不同版本/配置构建的。我建议您安装(原始GLUT早已过时),并确保您使用与应用程序相同的配置构建freeglut。您使用的GLUT版本是根据运行库的不同版本/配置构建的。我建议您安装(原始GLUT早已过时),并确保您使用与应用程序相同的配置构建freeglut。您使用的GLUT版本是根据运行库的不同版本/配置构建的。我建议您安装(原来的GLUT早已过时),并确保您使用与应用程序相同的配置构建freeglut。我现在使用freeglut,我有以下错误:编辑:现在错误只是它无法打开freeglut32.lib:\(我已将freeglut32.lib添加到链接器中)听起来freeglut32.lib的路径不在项目的库搜索路径中。你是对的,我的错,它是freeglut.lib,现在我的错误是:谢谢!同样,您需要确保配置是相同的。这里看起来一个是在发布模式下构建的,另一个是在调试模式下构建的。它需要是同一个运行时。我将其更改为的任何运行时都不起作用,我该怎么办?我现在正在使用freeglut,我有以下错误:编辑:现在错误只是它无法打开freeglut32.lib:\(我已将freeglut32.lib添加到链接器中)听起来freeglut32.lib的路径不在项目的库搜索路径中。你是对的,我的错,它是freeglut.lib,现在我的错误是:谢谢!同样,您需要确保配置是相同的。这里看起来一个是在发布模式下构建的,另一个是在调试模式下构建的。它需要是同一个运行时。我将其更改为的任何运行时都不起作用,我该怎么办?我现在正在使用freeglut,我有以下错误:编辑:现在错误只是它无法打开freeglut32.lib:\(我已将freeglut32.lib添加到链接器中)听起来freeglut32.lib的路径不在项目的库搜索路径中。你是对的,我的错,它是freeglut.lib,现在我的错误是:谢谢!同样,您需要确保配置是相同的。这里看起来一个是在发布模式下构建的,另一个是在调试模式下构建的。它需要是同一个运行时。我将其更改为的任何运行时都不起作用,我该怎么办?我现在正在使用freeglut,我有以下错误:编辑:现在错误只是它无法打开freeglut32.lib:\(我已将freeglut32.lib添加到链接器中)听起来freeglut32.lib的路径不在项目的库搜索路径中。你是对的,我的错,它是freeglut.lib,现在我的错误是:谢谢!同样,您需要确保配置是相同的。这里看起来一个是在发布模式下构建的,另一个是在调试模式下构建的。它需要是同一个运行时。我将其更改为的任何运行时都不起作用,我该怎么办?你有没有运行过这个示例?你有没有运行过这个示例?你有没有运行过这个示例?你有没有运行过这个示例?
Warning 23 warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\LINK RedBook
Warning 24 warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\MSVCRT.lib(cinitexe.obj) RedBook
Error 6 error LNK2005: _exit already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0dat.obj) RedBook
Error 21 error LNK2005: __XcptFilter already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(winxfltr.obj) RedBook
Error 20 error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(mlock.obj) RedBook
Error 19 error LNK2005: __lock already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(mlock.obj) RedBook
Error 8 error LNK2005: __ldused already defined in a previous module c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(fpinit.obj) RedBook
Error 1 error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(invarg.obj) RedBook
Error 5 error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0dat.obj) RedBook
Error 7 error LNK2005: __fltused already defined in a previous module c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(fpinit.obj) RedBook
Error 4 error LNK2005: __exit already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0dat.obj) RedBook
Error 22 error LNK2005: __configthreadlocale already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(wsetloca.obj) RedBook
Error 3 error LNK2005: __cexit already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0dat.obj) RedBook
Error 9 error LNK2005: __calloc_crt already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crtheap.obj) RedBook
Error 2 error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0dat.obj) RedBook
Error 15 error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0init.obj) RedBook
Error 14 error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0init.obj) RedBook
Error 17 error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0init.obj) RedBook
Error 16 error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(crt0init.obj) RedBook
Error 18 error LNK2005: ___set_app_type already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(errmode.obj) RedBook
Error 12 error LNK2005: ___crtUnhandledException already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(winapisupp.obj) RedBook
Error 11 error LNK2005: ___crtTerminateProcess already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(winapisupp.obj) RedBook
Error 10 error LNK2005: ___crtSetUnhandledExceptionFilter already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(winapisupp.obj) RedBook
Error 13 error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR110.dll) c:\Users\Naor\documents\visual studio 2012\Projects\RedBook\RedBook\libcmt.lib(hooks.obj) RedBook
Error 25 error LNK1169: one or more multiply defined symbols found c:\users\naor\documents\visual studio 2012\Projects\RedBook\Debug\RedBook.exe 1 1 RedBook
opengl32.lib;glu32.lib;