• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
GameCreator

Header Files

11 posts in this topic

Very beginner question but how the heck do header files work?

 

I'm using RakNet and have a cpp file with a bunch of functions using it and its variables.  Works great.  Then I made a function which was declared (?) in a .h file, as per below:

 

int getplayernumberfromguid(RakNetGUID id);

 

I then get a TON of "error C2065: 'RakNetGUID' : undeclared identifier" errors for the same line.

 

So, I figure, in my infinite wisdom: no problem - I'll just copy and paste the #include stuff from the top of the cpp file into the top of the h file.  If it works for one, it should work for the other.  Well, that just brings in a mess of new errors including errors inside the RakNet files which should have no issues whatsoever.

 

Any idea what I'm doing wrong?  How are you really supposed to do this?

 

Thanks in advance!

0

Share this post


Link to post
Share on other sites

Can you post every source/header file relevant to the problem (provided it's not too long)? It's hard to follow exactly what you did and what you could have done wrong.

1

Share this post


Link to post
Share on other sites

Thank you very much Trienco.  That actually clearly taught me quite a bit!  Here are the two relevant files.

 

networking.cpp

http://pastebin.com/PGpfVf9d

 

networking.h

http://pastebin.com/1Q77HBdZ

 

The latest change I made was trying to put

int getplayernumberfromguid(RakNetGUID id);

at the bottom of the h file to declare it, if that's the right word.  That's when this mess started.  If I declare it at the top of the cpp file then it all works.

 

By the way, I did also noticed that RakNetGUID is declared in RakNetTypes.h and I tried adding that too but it makes no difference.  Plus it was never needed for my cpp file so maybe it's declared or linked to in another h file??  Don't know.

 

My other guess is that it may have something to do with:

using namespace RakNet;

Not sure how that works across various files but including it in the h file didn't seem to help.

 

I may be over my head with this.  I'm still a little confused as to how what I'm doing could possible start generating errors in RakNet's code (which I didn't touch).

 

(As as sidenote, it's a little intimidating to know that at any time my code can break because I don't know enough and at one point maybe it'll be too complex for anyone to help.)

0

Share this post


Link to post
Share on other sites

I haven't read the article yet but I moved all but network.h includes to the header.  Now I get a bunch of redefinition errors, like so:

 

1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h(91): warning C4005: 'AF_IPX' : macro redefinition
1>          C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock.h(460) : see previous definition of 'AF_IPX'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h(131): warning C4005: 'AF_MAX' : macro redefinition
1>          C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock.h(479) : see previous definition of 'AF_MAX'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h(168): warning C4005: 'SO_DONTLINGER' : macro redefinition
1>          C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock.h(402) : see previous definition of 'SO_DONTLINGER'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h(212): error C2011: 'sockaddr' : 'struct' type redefinition
1>          C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock.h(485) : see declaration of 'sockaddr'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h(390): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h(390): error C3805: 'constant': unexpected token, expected either '}' or a ','

etc.

 

I'll have to reread these posts to get a better understanding and probably that article.

(I assume, by the way, that having two cpp files include network.h isn't an issue...)

Edited by GameCreator
0

Share this post


Link to post
Share on other sites

Only include winsock2.h

 

no ws2def.h

 

Its some time back that I created windows applications. But I think you can even ignore windows.h because it is included somewhere deep inside the winsock2.h

 

Anyways winsock2.h must be included before windows.h

0

Share this post


Link to post
Share on other sites

I don't have those includes in my code but RakNet does (and it's smart enough to know which goes first).  However, I'm using a second library which uses windows.h.  So... by moving the headers, is there a chance that their order got switched?  Because it was working before and all I did was move the headers from my network.cpp to my network.h (which is included in at least 2 cpp files).

Edited by GameCreator
0

Share this post


Link to post
Share on other sites

Think about two different scenarios.

 

A library/subsystem creator who has defined a lot of structures that need a specific order is the responsible that wants to make the usage, and thus the inclusion of headers, as easy as possible. This is why you find system header include statements in other include files. This makes the usage for the library function as easy as possible.

 

System-Header files are enclosed in <>.

 

The developer of a system/subsystem does not include his own header files from within header files, to have a better control about what is included within a single source files. Circular includes or other problems with undefined or double defined structures/defines and the like can be overcome if the application includes are only put into the source.

 

Application specific header files are enclosed in "".

 

Using <> or "" has todo with the search order of the pre-processor for include files.

 

Another thing is that pre-processor and compiler are two different things. The pre-processor creates a stream of text that results of processing any #directive. The compiler processes that stream after that processing has done. You can tell the compiler to only make the pre-processing step an put the result into a file/stdout. This way you can investigate the the order of files that are included and what the result of the pre-processing is.

 

Think of a define you made different to some system header file. You will not find the bug without have a look on the input stream to the compiler.

 

0

Share this post


Link to post
Share on other sites

Think about two different scenarios.

 

A library/subsystem creator who has defined a lot of structures that need a specific order is the responsible that wants to make the usage, and thus the inclusion of headers, as easy as possible. This is why you find system header include statements in other include files. This makes the usage for the library function as easy as possible.

 

System-Header files are enclosed in <>.

 

The developer of a system/subsystem does not include his own header files from within header files, to have a better control about what is included within a single source files. Circular includes or other problems with undefined or double defined structures/defines and the like can be overcome if the application includes are only put into the source.

 

Application specific header files are enclosed in "".

 

Using <> or "" has todo with the search order of the pre-processor for include files.

 

Another thing is that pre-processor and compiler are two different things. The pre-processor creates a stream of text that results of processing any #directive. The compiler processes that stream after that processing has done. You can tell the compiler to only make the pre-processing step an put the result into a file/stdout. This way you can investigate the the order of files that are included and what the result of the pre-processing is.

 

Think of a define you made different to some system header file. You will not find the bug without have a look on the input stream to the compiler.

 

This is very interesting i really didn't know what was behind the compiling process, can you recommend a couple of books about this kind of topics?

0

Share this post


Link to post
Share on other sites

Öh.

I learned this about 30 years ago. It is part of any C/C++ compiler description. On unix-style machines and I think on solaris as well the C pre-processor is a separat program cpp named and you will find descriptions on the man-pages.

 

I never used books to learn things. So I cannot recommend one.

0

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  
Followers 0