Visual Studio 2005 and OpenGL

This topic is 4307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello! When I used Dev-C++ it worked fine, but I never get anything to work in VS 2005 Express. I want to use OpenGL in VS 2005, but I am having problems with setting it up. I have followed a few tutorials but I can't get it to compile, the error I get is a linking error: "fatal error LNK 1120: 1 unresolved external." Just to explain how I did: I went to the project properties page, clicked 'Linker', then I clicked on the 'Input' label and typed in 'opengl32.lib glu32.lib' in the first row. I have made sure that the required DLLs are in the system directory, so that's not the problem. If anyone could help me out here I would be grateful! - Cerasti [Edited by - Heptagonal on November 9, 2007 9:42:46 AM]

Share on other sites
What exactly are those link error messages?

Share on other sites
I already have the platform SDK, but do you have to configure it with VS 2005?

(edit) When I installed it I followed those instructions.

The error:
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
fatal error LNK1120: 1 unresolved externals

Share on other sites
that's an error that one typically gets when trying to build a windows application using the console application template. Did you start a Win32 Project or a Win32 Console Application?

Share on other sites
Yes, but I unchecked 'Console application' and checked 'Windows application'.

Share on other sites
OK, I replicated your linker error. All I had to do was comment out my WinMain function. Let's see how you declare your WinMain function... post it up. Did you perhaps forget to define it or include that source file that contains it into your project?

Share on other sites
Here it is:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){	static HGLRC hRC;	static HDC hDC;	switch(message)	{		case WM_CREATE:			hDC = GetDC(hWnd);			hRC = wglCreateContext(hDC);			wglMakeCurrent(hDC,hRC);			break;		case WM_DESTROY:			wglMakeCurrent(hDC,NULL);			wglDeleteContext(hRC);			PostQuitMessage(0);			break;	}	return 0;}

Share on other sites
You might try including <windows.h> before any openGL header files, rather than afterwards. It's a longshot, but I had a similar problem before that was caused by that.

Share on other sites
Windows.h is already included in a file called stdafx.h which VS created for me, I don't know why it got there but I suppose it's important.

Share on other sites
That's not your WinMain function, that's your Window Procedure. Post your WinMain function, every win32 application must have one.

usually looks something like this:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int){ MSG msg; // code here return (int) msg.wParam;}

Share on other sites
That must be the problem, I don't have any WinMain function.

Share on other sites
ok i get a similar error ive been searching for hours any help. this code is copied right out oc Beginning Game Programing.. and still i get

1>------ Build started: Project: images1, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\me\Desktop\PPG\images1\Debug\images1.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\me\Desktop\PPG\images1\images1\Debug\BuildLog.htm"
1>images1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

code:

#include
#include
#include

#define APPTITLE "Kon'nichi wa, BITCHES!!!!"

//Protoype
BOOL InitInstance(HINSTANCE,int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char *szHello = "Kon'nichi wa, BITCHES!!!!";
RECT rt;
int x,y,n;
COLORREF c;

switch(message)
{
case WM_PAINT:
//gets the dimensions of the window
GetClientRect(hWnd, &rt);

//start drawing on device context
hdc = BeginPaint(hWnd,&ps);

//draw some text
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

//draw 1000 random pixels
for(int i =0 ; i <

Share on other sites
I assume you have an "int main()" somewhere in your code to start the app. Just replace the function declaration with

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)

and it should work.

Share on other sites
Quote:
 Windows.h is already included in a file called stdafx.h which VS created for me, I don't know why it got there but I suppose it's important.

Off-Topic: Don't create that type of project. When you create your project, in the settings window, (Where you chose 'Windows Project'), choose 'Empty Project' as well. Link to libraries with #pragma comment(lib, "mylibrary.lib") if you don't like going into the project linker settings.