C++ Opengl, unresolved externals after linking libraries

Started by
2 comments, last by MindOfCorruption97 11 years, 5 months ago
Hey all, this is my first post so I'll make it quick.
I currently have a problem in C++ where, after I compile, it prints an error in the console saying:

------ Build started: Project: OpenGL_1, Configuration: Debug Win32 ------
1> CreatingAWindow.cpp
1>CreatingAWindow.obj : error LNK2019: unresolved external symbol "void __cdecl EnableOpenGL(struct HWND__ *,struct HDC__ * *,struct HGLRC__ * *)" (?EnableOpenGL@@YAXPAUHWND__@@PAPAUHDC__@@PAPAUHGLRC__@@@Z) referenced in function _WinMain@16
1>C:\Users\MindOfCorruption97\Desktop\MyStuff\Programming\C++\SDL_OpenGL\Sandbox\OpenGL_1\Debug\OpenGL_1.exe : fatal error LNK1120: 1 unresolved externals

I linked the libraries because before the error was much larger.
After I linked the libraries there was only one error message left as you can see above.
Here is the code if you guys need it:

[source lang="cpp"]#include <windows.h>
#include <gl/gl.h>

//Function that handles messages sent to your window.
//hwnd is the handle to the window, uMsg is the message code, wParam and lParam contains more code about the message.
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void EnableOpenGL(HWND hwnd,HDC * hdc,HGLRC * hrc);
void DisableOpenGL(HWND hwnd,HDC hdc,HGLRC hrc);

//wWinMain is the Main method in a windows C++ program.
//hinstance is called "handle to an instance" or "handle to a module". It is used to identify the EXE.
//nCmdLine contains command line arguments. nCmdShow chooses whether it is minimized, maximized, or hidden.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
HWND hwnd;
HDC hdc;
HGLRC hrc;
MSG msg;
BOOL quit = FALSE;
float theta = 0.0f;

wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc; //Pointer to the Window Procedure(WindowProc).
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;//hInstance is used to handle the application instance.
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";//lpszClassName is a string that identifies the window class.
RegisterClass(&wc);//Uses the OS to register the window.

//Creates a new instance of the window.CreateWindowEx(Window style,Type of window,Title bar).
//WS_OVERLAPPEDWINDOW give the window a title bar and all that stuff.
hwnd = CreateWindow(
"GLSample","OPENGL Window Creation",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0,0,256,256,
NULL,NULL,hInstance,NULL);

EnableOpenGL(hwnd,&hdc,&hrc);

//Used to dispatch messages to the correct windows.
while(!quit)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
quit = TRUE;
}else
{
TranslateMessage(&msg);//Used to translate keyboard input.
DispatchMessage(&msg);//Returns the message for the next loop.
}
}else
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix();
glRotatef(theta,0.0f,0.0f,1.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f); glVertex2f(0.0f,1.0f);
glColor3f(0.0f,0.0f,1.0f); glVertex2f(0.87f,-0.5f);
glColor3f(0.0f,0.0f,1.0f); glVertex2f(-0.87f,-0.5f);
glEnd();
glPopMatrix();

SwapBuffers(hdc);

theta += 1.0f;
}
}

DisableOpenGL(hwnd,hdc,hrc);
DestroyWindow(hwnd);
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:return 0;
case WM_CLOSE:PostQuitMessage(0);return 0;
case WM_DESTROY:return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}

void EnableOpenGl(HWND hwnd,HDC * hdc,HGLRC * hrc)
{
PIXELFORMATDESCRIPTOR pfd;
int format;

*hdc = GetDC(hwnd);

ZeroMemory(&pfd,sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat(*hdc,&pfd);
SetPixelFormat(*hdc,format,&pfd);

*hrc = wglCreateContext(*hdc);
wglMakeCurrent(*hdc,*hrc);
}
void DisableOpenGL(HWND hwnd,HDC hdc,HGLRC hrc)
{
wglMakeCurrent(NULL,NULL);
wglDeleteContext(hrc);
ReleaseDC(hwnd,hdc);
}
[/source]
Help as soon as possible, thank you.
Advertisement
At the top, you declare EnableOpenGL, but your implementation of it near the bottom of the code is called EnableOpenGl (note the lowercase l).
void EnableOpenGL(HWND hwnd,HDC * hdc,HGLRC * hrc); <-- BIG L


end of file

void EnableOpenGl(HWND hwnd,HDC * hdc,HGLRC * hrc) <-- little l
At the top, you declare EnableOpenGL, but your implementation of it near the bottom of the code is called EnableOpenGl (note the lowercase l).
void EnableOpenGL(HWND hwnd,HDC * hdc,HGLRC * hrc); <-- BIG L end of file void EnableOpenGl(HWND hwnd,HDC * hdc,HGLRC * hrc) <-- little l


Thank you, I never knew that the problem was so simple.
Now it works great. smile.png

This topic is closed to new replies.

Advertisement