Jump to content
  • Advertisement
Sign in to follow this  
K A Z E

2 Questions: Including classes from other files and assembly language

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got two unrelated questions: 1) When I #include my image loader class if I don't add it to my project I get these link errors:
Image Loader Revampatation.obj : error LNK2019: unresolved external symbol "public: __thiscall Image::Image(void)" (??0Image@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'Images''(void)" (??__EImages@@YAXXZ)
Image Loader Revampatation.obj : error LNK2019: unresolved external symbol "public: __thiscall Image::~Image(void)" (??1Image@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'Images''(void)" (??__EImages@@YAXXZ)
C:\Documents and Settings\Owner\Desktop\Icon Folder\OpenGL Programming Stuff\Image Loader Revampatation\Debug\Image Loader Revampatation.exe : fatal error LNK1120: 2 unresolved externals

I notice that if I include a structure/class w/o member functions, I do not get these errors. Why is this? And how do I fix it? This isn't really a problem, this far I've just been including my image loader class into all my projects which solves the problem, but I just want to know. 2) I've heard of a thing called assembly language. And have seen some of it. And stuff written in assembly is supposed to be faster than stuff written in C++. Well what is assembly language, and why does it run faster? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You are getting link errors because the linker is unable to find definitions for the functions listed. This is likely because you have used the preprocessor to #include the header containing the Image class's definition, but have not added its source file to the project or otherwise specified that the compiler should compile it and generate an .obj file for the linker to use.

Remember -- #include is just a preprocessor command that does textual substitution. It is not equivalent to more powerful constructs like C#'s using and Python's import. The compiler only compiles one translation unit at a time, independantly. You can work around this state of affairs by using #include to copy the appropriate .cpp file into the translation unit, but this is a bad idea and will only work in certain, very isolated circumstances (usually it will just cause multiple definition errors). Don't do it. Just add your source file to your project like you are supposed to.

You don't get the link errors when you #include a file containing a construct with no member functions because there are no member functions that have been tucked away into their own source file, and thus, nothing for the linker to try to resolve.

Assembly language is a "more direct" mapping to machine code than a language like C++. It is not faster, except in some circumstances where you really know what you are doing and the compiler cannot produce decent machine code. These situations are quite rare nowadays and are becoming increasely rarer.

Share this post


Link to post
Share on other sites
Quote:
Original post by K A Z E
2) I've heard of a thing called assembly language. And have seen some of it. And stuff written in assembly is supposed to be faster than stuff written in C++. Well what is assembly language, and why does it run faster?

Thanks in advance.


http://en.wikipedia.org/wiki/Assembly_language

http://en.wikipedia.org/wiki/X86_assembly_language

Also, you might want to run a forum search for "assembly language" here at GameDev.net

Share this post


Link to post
Share on other sites
"#include is just a preprocessor command that does textual substitution"

So #include just "pastes" the code in the header in the spot I #include it? And it has link errors because it finds the declarations of the functions but not the actual code for them then?

Also, about the files in the include directory. They have headers there and the actual workings of the functions and stuff in the headers are in the libs I link right? I've opened 'em up with notepad and found binary and some ascii. What's the deal with this? I'm kind of vague on why/how this is done and stuff. Why do it like this? Why not write out the function code and stuff in a cpp file? Also HOW do you do it like this?

And thanks for the reply jpetrie.

EDIT: Ah. Thanks for the links everyman.

Share this post


Link to post
Share on other sites
Quote:
Original post by K A Z E
"#include is just a preprocessor command that does textual substitution"

So #include just "pastes" the code in the header in the spot I #include it? And it has link errors because it finds the declarations of the functions but not the actual code for them then?


Preprocessor
C Preprocessor
Header file
Code reuse

Quote:
Original post by K A Z E
Also, about the files in the include directory. They have headers there and the actual workings of the functions and stuff in the headers are in the libs I link right? I've opened 'em up with notepad and found binary and some ascii. What's the deal with this? I'm kind of vague on why/how this is done and stuff. Why do it like this? Why not write out the function code and stuff in a cpp file? Also HOW do you do it like this?

Library
Static Library
Dynamic Library

Again, you might want to search the GameDev.net archives for similar discussions covering basically all of your questions, including answers to everything you may want to know.





Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!