Archived

This topic is now archived and is closed to further replies.

include headers

This topic is 5577 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

My appoligies for asking a "Newbie" question but, I think this is very important.. What is the logic behind the order of compiling files? I''ve got certain files which I need to be compiled before others..ummm an example: //in main.h #include "utils.h" #include "win32.h" When compiling my project it will go thru my win32.h and say stuff defined in utils.h could were not defined.. No matter how hard I try I can''t understand the way it selects the order to compile all the different files.. Thanks :D -Shadow http://nap.mega.net.kg

Share this post


Link to post
Share on other sites
I don''t have time to write an essay about headers etc, but want to point out that you shall never define any function in a header file. You may declare them there, but no real code should never be placed in a header file (or any other file that you #include), only in .c/.cpp files that will be compiled.

Share this post


Link to post
Share on other sites
quote:
Have you tried including utils.h in main.cpp?

Yip..
I have tried this..no change..

Here's the Problem: When I compile the output is this:

Compiling...
Utils.cpp
Building: Utils.h
Building: glMain.h
Building: glLog.h
Building: glUtils.h
Building: Win32.h
Building: glPipe.h
d:\projects\c++\diablo\diablogl\glpipe.h(43) : error C2061:
syntax error : identifier 'RGBA'


But 'RGBA' is defined in Utils.h so I'm now confused!

-Shadow


http://nap.mega.net.kg



[edited by - shadowmaster on September 1, 2002 9:57:14 AM]

Share this post


Link to post
Share on other sites
I'm using Visual C++.
I've Sorted the problem not the way, I would have liked to, by moving bits of code from glMain.h and glUtils.h to the glPipe.h file...problem is my code is now no longer orginized and I still don't understand why I'm got that error ...

Here's whats in the files...
Utils.h
Maths Functions like Sine/Cosine look up and other little funcions
glMain.h
Hold all the Macros and Definitions used by all files
glLog.h
Make a debug log
glUtils.h
Tools for OpenGL, eg Screen shot function
Win32.h
Windows Functions eg Make Window / Resize
glPipe.h
Handles Redering, Initilizing etc of OpenGL

Thanks
-Shadow



http://nap.mega.net.kg



[edited by - shadowmaster on September 1, 2002 12:41:22 AM]

Share this post


Link to post
Share on other sites
What are you doing!!! You put code in header files?!?! and then include them into other files! Never, ever, do that! You shall put only declarations, typedefs, structs, #defines, etc. in header files, no code whatsoever! The code goes into the .cpp files, which you shall compile build. Into those you include your header files. Man, if you''re doing what I think your doing, you need to get back to the books and read some basics of organizing C/C++ code.

Sorry for the harsch words, no pun intended

Share this post


Link to post
Share on other sites
Oops, sorry. I hoped I was wrong, and I was

The thing I wonder, though, is that your compiler output said "Building *.h". Cannot remember mine ever building header files. (Can be wrong, though.)

Hopefully I shall not offend you again, but I''ll try to explain in a quickie how C/C++ files are built:

In a project you add one or more "code" files; usually in the form of .cpp files, where all code that is going to be translated into machine instruction are and other constant data. When building the project, the compiler compiles each of these "code" files, alone or independently, into object files containing the native machine instructions plus linking information. Due to that all "code" files are build independently of each other, all functions, variables etc. used in each must be declared (not defined) so the compiler knows what they are. All those declarations are usually collected in one or more header files, which are included in all files that need them.
When all "code" files have been compiled into object files, they are sent to the linker to produce an executable, which resolves all function calls etc located in other object files.

Messy? I know I''m very bad explaining... but I''m trying the best I can to help you solve your problem. Could it be how you have set up your project? Perhaps added .h files as "code" files or something? (is that possible?)

If you still have problem here, please list all files in your project/workspace, and which other files they include, and perhaps we can be able to help you sort this out.

Share this post


Link to post
Share on other sites
Btw, is Utils.h included in glpipe.h (or all files which include glpipe.h)? It must be. As I tried to explain, all files in the project are built independently before the linker stage, so all delarations msu be included in all files that uses them. It''s not good enough if they are declared somewhere in the workspace, or are in another file built.

Share this post


Link to post
Share on other sites
The *.h files are not actualy built..I just added "#pragma message" so that I could found out were it's looking... Like I said I've fixed it..I think I'll leave it as is now. I just wish I knew why it was doing that..

Thanks a heap for all your help tho
-Shadow


http://nap.mega.net.kg



[edited by - shadowmaster on September 3, 2002 3:08:06 AM]

Share this post


Link to post
Share on other sites