[英]Cant compile an example from opengl redbook
so i have this code: 所以我有这段代码:
#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();
}
When i run it i get: 当我运行它时,我得到:
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
I followed what @Mario said here: error LNK2019: unresolved external symbol _LoadShaders referenced in function "void __cdecl init(void)" (?init@@YAXXZ) 我遵循@Mario在这里说的内容: 错误LNK2019:函数“ void __cdecl init(void)”中引用的未解析的外部符号_LoadShaders(?init @@ YAXXZ)
And I have this on my Linker Additional Dependencies : 我在我的链接器其他依赖项上有此选项:
opengl32.lib;glu32.lib;
When I add glut32.lib I get an error that it could not be opened, so I downloaded it and added it to C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Lib But i still get the same error. 当我添加glut32.lib时,我得到一个无法打开的错误,因此我下载了它并将其添加到C:\\ Program Files(x86)\\ Microsoft SDKs \\ Windows \\ v7.0A \\ Lib但我仍然得到相同的结果错误。
The files for the example's and all the lib and stuff can be found here: link 该示例的文件以及所有的lib和东西可以在这里找到: 链接
EDIT : And my Runtime Library on Code Generation is : Multi-threaded DLL (/MD) 编辑:我在代码生成上的运行时库是: 多线程DLL(/ MD)
The version of GLUT you're using is built against a different version/configuration of the runtime library. 您使用的GLUT版本是针对运行时库的其他版本/配置构建的。 I suggest you install freeglut (the original GLUT is long-dead), and make sure you build freeglut with the same configuration as you use for your application.
我建议您安装freeglut (原始的GLUT是已死的),并确保使用与您的应用程序相同的配置来构建freeglut。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.