Unresolved external symbols?
I copied this code exactly from the book, but I get unresolved external symbols. Its supposed to display a rotating red triangle on the screen. Can someone please copy/paste this into their compiler and tell me what you think?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <gl/gl.h> //Standard OpenGL include
#include <gl/glu.h>//OpenGL utilities
#include <gl/glaux.h> //OpenGL auxiliary functions
//Global Variables
float angle = 0.0f; //Current angle of the rotating triangle
HDC g_HDC; //global device context
//Function to set the pixel format for the device
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat; //your pixel format index
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), //Size of the structure
1, //Version, always set to 1
PFD_DRAW_TO_WINDOW | //support window
PFD_SUPPORT_OPENGL | //support openGL
PFD_DOUBLEBUFFER, //support double buffering
PFD_TYPE_RGBA, //RGBA color mode
32, //go for 32 bit color mode
0, 0, 0, 0, 0, 0, //Ignore color bits, not used
0, //No alpha buffer
0, //Ignore shift bit
0, //No accumulation buffer
0, 0, 0, 0, //Ignore accumulation bits
16, //16 bit Z buffer size
0, //no stencil buffer
0, //no auxiliary buffer
PFD_MAIN_PLANE, //main drawing plane
0, //reserved
0, 0, 0 }; //layer masks ignored
//Choose best matching pixel format, return index
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
//set pixel format to device context
SetPixelFormat(hDC, nPixelFormat, &pfd);
}
//Event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC; //rendering context
static HDC hDC; //device context
char string[] = "Hello, world!"; //text to be displayed
int width, height; //window width and height
switch(message)
{
case WM_CREATE:
hDC = GetDC(hwnd); //get current window''s device context
g_HDC = hDC;
SetupPixelFormat(hDC); //Call your pixel format setup function
//create rendering context and make it current
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
return 0;
break;
case WM_CLOSE:
//deselect rendering context and delete it
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
//sent WM_QUIT to message queue
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam); //retrieve width and height
width = LOWORD(lParam);
if(height == 0) //don''t want a divide by zero
{
height = 1;
}
//Reset the viewport to new dimensions
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); //set projection matrix
glLoadIdentity(); //reset projection matrix
//calculate aspect ratio of window
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW); //Set modelview matrix
glLoadIdentity(); //reset modelview matrix
return 0;
break;
default:
break;
}
return(DefWindowProc(hwnd, message, wParam, lParam));
}
//main windows entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass; //window class
HWND hwnd; //Window handle
MSG msg; //message
bool done;
//fill out the window class structure
windowClass.style = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 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; //don''t need background
windowClass.lpszMenuName = NULL; //no menu
//Register the window class
if(!RegisterClassEx(&windowClass))
return 0;
//class registered, so now create your window
hwnd = CreateWindowEx(NULL, //extended style
"MyClass", //class name
"The OpenGL Window Application!",//app name
WS_OVERLAPPEDWINDOW | WS_VISIBLE| //window style
WS_SYSMENU | WS_CLIPCHILDREN | //
WS_CLIPSIBLINGS,
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
if(!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW); //display the window
UpdateWindow(hwnd); //update the window
done = false; //loop variable
while(!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if(msg.message == WM_QUIT) //if you receive a WM_QUIT message?
{
done = true;
}
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 rotation angle counter
if(angle >= 360.0f)
{
angle = 0.0f; //reset angle counter
}
glTranslatef(0.0f, 0.0f, -5.0f); //move back 5 units
glRotatef(angle, 0.0f, 0.0f, 1.0f);//draw the rectangle
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);
TranslateMessage(&msg); //translate/dispatch to envent queue
DispatchMessage(&msg);
}
}
return int(msg.wParam);
// MessageBox(NULL, "\Hello, world!", "My first windows application", NULL);
}
You are not linking to OpenGL32.lib and glu32.lib.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
The book didn''t say to do that, but I tried it, and it can''t find OpenGL32.lib. The file doesn''t exist.
quote:Original post by EGD EricYeah it does, on page 9. And on page 8 it tells you what to do to make sure your compiler can find it.
The book didn''t say to do that.
Sorry I didn''t reply till now, I started a new job.
I tried downloading the source code from that site, but couldn''t find it. Nor is it on the CD that comes with the book.
You''re right of course: it does say so in the book. I figure they should have mentioned that again, because I had forgotten about it, having read the previous chapter on a previous day.
Now, I''ve followed page 8 & 9''s instructions implicitly:
I put the following files in a folder I created called "GL" in the include folder of visual studio.net:
GL.h
Glu.h
Glaux.h
I also put the lib files into the "Include" file. It still gives me: Unresolved external symbols. Here''s my code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
//#include <OpenGL32.lib>
//#include <glu32.lib>
#include <gl/gl.h> //Standard OpenGL include
#include <gl/glu.h>//OpenGL utilities
#include <gl/glaux.h> //OpenGL auxiliary functions
//Global Variables
float angle = 0.0f; //Current angle of the rotating triangle
HDC g_HDC; //global device context
//Function to set the pixel format for the device
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat; //your pixel format index
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), //Size of the structure
1, //Version, always set to 1
PFD_DRAW_TO_WINDOW | //support window
PFD_SUPPORT_OPENGL | //support openGL
PFD_DOUBLEBUFFER, //support double buffering
PFD_TYPE_RGBA, //RGBA color mode
32, //go for 32 bit color mode
0, 0, 0, 0, 0, 0, //Ignore color bits, not used
0, //No alpha buffer
0, //Ignore shift bit
0, //No accumulation buffer
0, 0, 0, 0, //Ignore accumulation bits
16, //16 bit Z buffer size
0, //no stencil buffer
0, //no auxiliary buffer
PFD_MAIN_PLANE, //main drawing plane
0, //reserved
0, 0, 0 }; //layer masks ignored
//Choose best matching pixel format, return index
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
//set pixel format to device context
SetPixelFormat(hDC, nPixelFormat, &pfd);
}
//Event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC; //rendering context
static HDC hDC; //device context
char string[] = "Hello, world!"; //text to be displayed
int width, height; //window width and height
switch(message)
{
case WM_CREATE:
hDC = GetDC(hwnd); //get current window''s device context
g_HDC = hDC;
SetupPixelFormat(hDC); //Call your pixel format setup function
//create rendering context and make it current
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
return 0;
break;
case WM_CLOSE:
//deselect rendering context and delete it
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
//sent WM_QUIT to message queue
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam); //retrieve width and height
width = LOWORD(lParam);
if(height == 0) //don''t want a divide by zero
{
height = 1;
}
//Reset the viewport to new dimensions
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); //set projection matrix
glLoadIdentity(); //reset projection matrix
//calculate aspect ratio of window
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW); //Set modelview matrix
glLoadIdentity(); //reset modelview matrix
return 0;
break;
default:
break;
}
return(DefWindowProc(hwnd, message, wParam, lParam));
}
//main windows entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass; //window class
HWND hwnd; //Window handle
MSG msg; //message
bool done;
//fill out the window class structure
windowClass.style = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 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; //don''t need background
windowClass.lpszMenuName = NULL; //no menu
//Register the window class
if(!RegisterClassEx(&windowClass))
return 0;
//class registered, so now create your window
hwnd = CreateWindowEx(NULL, //extended style
"MyClass", //class name
"The OpenGL Window Application!",//app name
WS_OVERLAPPEDWINDOW | WS_VISIBLE| //window style
WS_SYSMENU | WS_CLIPCHILDREN | //
WS_CLIPSIBLINGS,
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
if(!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW); //display the window
UpdateWindow(hwnd); //update the window
done = false; //loop variable
while(!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if(msg.message == WM_QUIT) //if you receive a WM_QUIT message?
{
done = true;
}
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 rotation angle counter
if(angle >= 360.0f)
{
angle = 0.0f; //reset angle counter
}
glTranslatef(0.0f, 0.0f, -5.0f); //move back 5 units
glRotatef(angle, 0.0f, 0.0f, 1.0f);//draw the rectangle
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);
TranslateMessage(&msg); //translate/dispatch to envent queue
DispatchMessage(&msg);
}
}
return int(msg.wParam);
// MessageBox(NULL, "\Hello, world!", "My first windows application", NULL);
}
I tried downloading the source code from that site, but couldn''t find it. Nor is it on the CD that comes with the book.
You''re right of course: it does say so in the book. I figure they should have mentioned that again, because I had forgotten about it, having read the previous chapter on a previous day.
Now, I''ve followed page 8 & 9''s instructions implicitly:
I put the following files in a folder I created called "GL" in the include folder of visual studio.net:
GL.h
Glu.h
Glaux.h
I also put the lib files into the "Include" file. It still gives me: Unresolved external symbols. Here''s my code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
//#include <OpenGL32.lib>
//#include <glu32.lib>
#include <gl/gl.h> //Standard OpenGL include
#include <gl/glu.h>//OpenGL utilities
#include <gl/glaux.h> //OpenGL auxiliary functions
//Global Variables
float angle = 0.0f; //Current angle of the rotating triangle
HDC g_HDC; //global device context
//Function to set the pixel format for the device
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat; //your pixel format index
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), //Size of the structure
1, //Version, always set to 1
PFD_DRAW_TO_WINDOW | //support window
PFD_SUPPORT_OPENGL | //support openGL
PFD_DOUBLEBUFFER, //support double buffering
PFD_TYPE_RGBA, //RGBA color mode
32, //go for 32 bit color mode
0, 0, 0, 0, 0, 0, //Ignore color bits, not used
0, //No alpha buffer
0, //Ignore shift bit
0, //No accumulation buffer
0, 0, 0, 0, //Ignore accumulation bits
16, //16 bit Z buffer size
0, //no stencil buffer
0, //no auxiliary buffer
PFD_MAIN_PLANE, //main drawing plane
0, //reserved
0, 0, 0 }; //layer masks ignored
//Choose best matching pixel format, return index
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
//set pixel format to device context
SetPixelFormat(hDC, nPixelFormat, &pfd);
}
//Event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC; //rendering context
static HDC hDC; //device context
char string[] = "Hello, world!"; //text to be displayed
int width, height; //window width and height
switch(message)
{
case WM_CREATE:
hDC = GetDC(hwnd); //get current window''s device context
g_HDC = hDC;
SetupPixelFormat(hDC); //Call your pixel format setup function
//create rendering context and make it current
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
return 0;
break;
case WM_CLOSE:
//deselect rendering context and delete it
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
//sent WM_QUIT to message queue
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam); //retrieve width and height
width = LOWORD(lParam);
if(height == 0) //don''t want a divide by zero
{
height = 1;
}
//Reset the viewport to new dimensions
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); //set projection matrix
glLoadIdentity(); //reset projection matrix
//calculate aspect ratio of window
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW); //Set modelview matrix
glLoadIdentity(); //reset modelview matrix
return 0;
break;
default:
break;
}
return(DefWindowProc(hwnd, message, wParam, lParam));
}
//main windows entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass; //window class
HWND hwnd; //Window handle
MSG msg; //message
bool done;
//fill out the window class structure
windowClass.style = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 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; //don''t need background
windowClass.lpszMenuName = NULL; //no menu
//Register the window class
if(!RegisterClassEx(&windowClass))
return 0;
//class registered, so now create your window
hwnd = CreateWindowEx(NULL, //extended style
"MyClass", //class name
"The OpenGL Window Application!",//app name
WS_OVERLAPPEDWINDOW | WS_VISIBLE| //window style
WS_SYSMENU | WS_CLIPCHILDREN | //
WS_CLIPSIBLINGS,
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
if(!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW); //display the window
UpdateWindow(hwnd); //update the window
done = false; //loop variable
while(!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if(msg.message == WM_QUIT) //if you receive a WM_QUIT message?
{
done = true;
}
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 rotation angle counter
if(angle >= 360.0f)
{
angle = 0.0f; //reset angle counter
}
glTranslatef(0.0f, 0.0f, -5.0f); //move back 5 units
glRotatef(angle, 0.0f, 0.0f, 1.0f);//draw the rectangle
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);
TranslateMessage(&msg); //translate/dispatch to envent queue
DispatchMessage(&msg);
}
}
return int(msg.wParam);
// MessageBox(NULL, "\Hello, world!", "My first windows application", NULL);
}
hey you cannot include libs by
#include
but they are included with
#pragma comment(lib,"xxx.lib")
(and (of course) they have to be copied to your Lib directory)
---why don''t we have assembler forum?--
#include
but they are included with
#pragma comment(lib,"xxx.lib")
(and (of course) they have to be copied to your Lib directory)
---why don''t we have assembler forum?--
libs arent included, they are linked and thats usually not done in the source code (except that proprietary vc pragma stuff).
i still cant imagine the book telling you to copy it to the include directory or to use include.
i still cant imagine the book telling you to copy it to the include directory or to use include.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement