Advertisement

Problem with linking the file

Started by February 10, 2003 04:43 PM
2 comments, last by DotDKay 21 years, 9 months ago
Hi I hope you guys can help me out with a code examble from the book "Opengl Game programming". It´s the last examble in chapter 2, where the plan is to make triangle in red, spinning on a black background. Im using Visual C++ 6.0, but i get 15 errors while linking, the errors are: --------------------Configuration: fshoot - Win32 Debug-------------------- Compiling... fshoot.cpp Linking... fshoot.obj : error LNK2001: unresolved external symbol _gluPerspective@32 fshoot.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0 fshoot.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4 fshoot.obj : error LNK2001: unresolved external symbol __imp__glViewport@16 fshoot.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4 fshoot.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8 fshoot.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4 fshoot.obj : error LNK2001: unresolved external symbol __imp__glEnd@0 fshoot.obj : error LNK2001: unresolved external symbol __imp__glVertex3f@12 fshoot.obj : error LNK2001: unresolved external symbol __imp__glBegin@4 fshoot.obj : error LNK2001: unresolved external symbol __imp__glColor3f@12 fshoot.obj : error LNK2001: unresolved external symbol __imp__glRotatef@16 fshoot.obj : error LNK2001: unresolved external symbol __imp__glTranslatef@12 fshoot.obj : error LNK2001: unresolved external symbol __imp__glClear@4 Debug/fshoot.exe : fatal error LNK1120: 14 unresolved externals Error executing link.exe. fshoot.exe - 15 error(s), 0 warning(s) The Sourcecode: #define WIN32_LEAN_AND_MEAN // trim the excess fat from Windows #include <windows.h> // standard Windows app include #include <gl/gl.h> #include <gl/glu.h> #include <gl/glaux.h> ///// Global Variables float angle = 0.0f; HDC g_HDC; void SetupPixelFormat(HDC hDC) { int nPixelFormat; // your pixel format index static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; // choose best matching pixel format, return index nPixelFormat = ChoosePixelFormat(hDC, &pfd); // set pixel format to device context SetPixelFormat(hDC, nPixelFormat, &pfd); } // the Windows Procedure event handler LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; static HDC hDC; char string[] = "Hello, world!"; // text to be displayed int width, height; switch(message) { case WM_CREATE: // window is being created hDC = GetDC(hwnd); g_HDC = hDC; SetupPixelFormat(hDC); // create rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); return 0; break; case WM_CLOSE: // windows is closing // desekect rendering context and delete it wglMakeCurrent(hDC, NULL); wglDeleteContext(hRC); // send WM_QUIT to message queue PostQuitMessage(0); return 0; break; case WM_SIZE: height = HIWORD(lParam); width = LOWORD(lParam); if (height==0) { height=1; } //reset the viewport to new dimensions glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // calculate aspect ratio of window gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return 0; break; default: break; } return (DefWindowProc(hwnd, message, wParam, lParam)); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX windowClass; // window class HWND hwnd; // window handle MSG msg; // message bool done; // flag saying when our app is complete // fill out the window class structure windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow windowClass.hbrBackground = NULL; // white background windowClass.lpszMenuName = NULL; // no menu windowClass.lpszClassName = "MyClass"; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon // register the windows class if (!RegisterClassEx(&windowClass)) return 0; // class registered, so now create our window hwnd = CreateWindowEx(NULL, // extended style "MyClass", // class name "The OpenGL Window Application!", // app name WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, // style 100, 100, // x,y coordinate 400, 400, // width, height NULL, // handle to parent NULL, // handle to menu hInstance, // application instance NULL); // no extra params // check if window creation failed (hwnd would equal NULL) if (!hwnd) return 0; ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); done = false; // intialize the loop condition variable // main message loop while (!done) { PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE); if (msg.message == WM_QUIT) // do we receive a WM_QUIT message? { done = true; // if so, time to quit the application } else { // do rendering here // clear screen and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // reset modelview matrix angle = angle + 0.1f; // increase your rotation angle counter if (angle >= 360.0f) // reset angle counter angle = 0.0f; glTranslatef(0.0f,0.0f,-5.0f); // move back 5 units glRotatef(angle, 0.0f,0.0f,1.0f); // rotate along z-axis glColor3f(1.0f,0.0f,0.0f); // set color to red glBegin(GL_TRIANGLES); // draw the triangle glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glEnd(); SwapBuffers(g_HDC); // bring back buffer to foreground TranslateMessage(&msg); // translate and dispatch to event queue DispatchMessage(&msg); } } return msg.wParam; }
doesn''t book have instructions on how to set up your compiler?
Advertisement
Here''s a link that will tell you how to set up MSVC for OpenGL programming:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
I had similiar problems once, and I found out it was my include.h...

after putting them in order the program needed the other files, it worked correctly.

This topic is closed to new replies.

Advertisement