Sign in to follow this  
furnace

Frustrating..! Original code works, but copied+pasted code doesn't?!

Recommended Posts

Hey, I'm using Visual Studio .Net 2003 and am looking at NeHe's OpenGL tutorials, but this problem's really annoying me (mostly because I know it's me thats doing something wrong). I go to File->New->Project, I get that choice of projects to start, so I chose "Empty Project (.Net)" and call it "01-ogl-win". Then you have the solution explorer on the right, so I right click "Source Files" and go Add->Add New Item->C++ File (.cpp), and call it main (well, main.cpp). This is where my problem is... I'm looking at NeHe's first lesson: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01 Scroll right to the bottom of that page, and you can download the Visual Studio .Net code for the tutorial. If I do that, open it, I can build and execute the DOWNLOADED code no problem. However, if I have the EXACT SAME CODE in the .cpp file I have just created in the way I just explained, I get 14 "Unresolved Externals" errors! Basically, I'm completely confused, and I'm sure it's something wrong with the way I'm setting up my project. Please, if you can... help me! :) Thanks!

Share this post


Link to post
Share on other sites
There's more to it than just copying in code. You need to configure the project settings as well. In specific, you need to link libraries to it. Nehe's lesson 1 explains that.

the unresolved externals are basically stuff defined in those libraries, that can't be found because you haven't linked them to the project.

Share this post


Link to post
Share on other sites
You need to include:
OpenGL32.lib GLu32.lib and GLaux.lib

To include those you may need to go through a process such as this (i am using visual studio 2005):
project properties->linker->input->additional dependencies

An alternate that might work is:

#pragma comment (lib, "OpenGL32.lib")
#pragma comment (lib, "GLu32.lib")
#pragma comment (lib, "GLaux.lib")

Share this post


Link to post
Share on other sites
Thanks for your help, guys :-)

I've got it working now. I knew I was doing something wrong..!

In the C++ evening courses we didn't do anything as far as additional resources are concerned :( I didn't learn as much as I thought it would teach me, only basic programming and some (seemingly dodgy) Windows programming :-P

Share this post


Link to post
Share on other sites
Quote:
Original post by furnace
I get 14 "Unresolved Externals" errors!


These are linker errors. If you have a linker error, your .cpp files have compiled fine, and the problem lies with your project settings.

"Unresolved External" is linkerspeak for "You told me that these functions exist (via headers), but you never gave me their implementations!". This can mean a few things:

1) If the unresolved external is for a function which you were supposed to have written:
1.a) You forgot to implement the function at all (the implementation can't be found because it doesn't exist)
1.b) You made a typeo implementing the function (e.g. you implemented Pine instead of Pie, and so your linker can't find it)
1.c) You screwed up your build system badly enough that it isn't even linking together all the right .o files (generated from the .cpp files)

2) If the unresolved external is for a function of a library you didn't write yourself (e.g. "Unresolved external to glBegin@4"):
2.a) You forgot to add the relevant .lib to your linker settings (the implementation can't be found because you forgot to tell your linker where to find said implementation)
2.b) Your .lib was built with vastly different settings than whatever you're trying to use said .lib with (e.g. you compiled the .lib with one default calling convention (e.g. stdcall), and tried to use it with a seperate default in your .exe/.dll (e.g. fastcall))

Share this post


Link to post
Share on other sites
Thanks monkey :)

I didn't want to start a new thread for this little question, but I've never come across this before:

gluPerspective(45.0f,(GLdouble)width/(GLdouble)height,0.1f,100.0f);

See where it says 45.0f, 0.1f and 100.0f..?

What's the 'f'? Does it denote the number as a float?

Do you know anywhere I can read more about these (can you do 'i' for integer or anything like that?) - I don't really know what to google to find out more about it!

Thanks in advance

Share this post


Link to post
Share on other sites
the f denotes a floating point literal. I don't belive that i works simply because it's unnecessary - an integer with no suffix specifies an integral literal



10 - integer literal
10.0f - floating point literal
10.0 - double literal



The f differentiates between a double precision literal and a single precision floating point literal

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this