HPP and CPP 
Author Message
 HPP and CPP

I just started using Visual C 6 SP4 (i do only win32 console exe)
a big question: it seems that VC compiles ALL *.cpp files in the project
*separately* and then it links all obj files in an exe.

ok. now, I've an header STD.HPP
which starts as usual:
#ifndef _MYSTDHPP_
#define _MYSTDHPP_
#include <...>
#endif

all the .cpp files in the project start with
#ifndef _MYSTDHPP_
#include "std.hpp"
#endif

and the file MAIN.CPP where the main is starts with

#include "a.cpp"
#include "b.cpp"

when I "rebuild all", all the .cpp are compiled ok, but the linker errors
repeatedly, saying "multiple symbols"
(xxxx in "main.obj" already defined in "a.cpp")

to make it work, I renamed
a.cpp -> a.hpp
etc.

and now it runs.

Any hint? Is this a standard behaviour? Am I doing something wrong?

--
 The set of solutions is never empty.
 Two solutions together form a new problem.
-- Mycroft Holmes



Mon, 12 May 2003 03:00:00 GMT  
 HPP and CPP

The normal thing to do is to revert to the first behavior where each .cpp
file gets compiled separately and
the linker links all together to create the exe.

What you're doing is conceptually no different from having a large .cpp file
which works, but introduce problems:
 a) a Change to any file forces re-compilation of all the files
 b) every file 'knows' everything about the contents of all the other files.

 Also compiling separate modules in separate files allows:
 c) pre-compilation of shared headers
 d) possibly using different compilation flags for different modules.

There are probably other advantages that I'm missing. However all these the
most importants are (a) if your project is non trivial, and (b) so that
exports from modules are clearly defined. This last point is also very
important if more than one person works on the project.

Salim.


Quote:
> I just started using Visual C 6 SP4 (i do only win32 console exe)
> a big question: it seems that VC compiles ALL *.cpp files in the project
> *separately* and then it links all obj files in an exe.

> ok. now, I've an header STD.HPP
> which starts as usual:
> #ifndef _MYSTDHPP_
> #define _MYSTDHPP_
> #include <...>
> #endif

> all the .cpp files in the project start with
> #ifndef _MYSTDHPP_
> #include "std.hpp"
> #endif

> and the file MAIN.CPP where the main is starts with

> #include "a.cpp"
> #include "b.cpp"

> when I "rebuild all", all the .cpp are compiled ok, but the linker errors
> repeatedly, saying "multiple symbols"
> (xxxx in "main.obj" already defined in "a.cpp")

> to make it work, I renamed
> a.cpp -> a.hpp
> etc.

> and now it runs.

> Any hint? Is this a standard behaviour? Am I doing something wrong?

> --
>  The set of solutions is never empty.
>  Two solutions together form a new problem.
> -- Mycroft Holmes



Fri, 16 May 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. HPP and CPP

2. HPP and CPP files

3. HPP and CPP

4. DEBUGGER DOCMULTI.CPP and DOCTEMPL.CPP

5. .h vs. hpp

6. hpp extension in File Open Dialog

7. .hpp files in Add Files To Project dialog

8. Two P's or not 2P's (HPP or H)

9. hpp file!

10. accessing a CMyAppView.cpp function from outside CMyAppView.cpp?

11. How to use DWebBroserevent in a cpp program ( cpp link with IE 3.0)?

12. Compiling a cpp file using the managed compiler !

 

 
Powered by phpBB® Forum Software