please dont rip this site

The C and C++ Programming Languages

Large Projects

Peter L. Peres [plp at ACTCOM.CO.IL] says

The keys to larger C projects are header files and build scripts.

The bug that causes you trouble is a very sane and useful ANSI C feature: Symbols declared in a module are not visible to other modules unless they are declared in the module that uses them as external or as function prototypes.

For example a function int foo(void); shall appear as int foo(void); in the main file, and a global variable int bar shall appear as extern int bar; in same. Of course you don't write them there, you include a library header file instead.

In other words, when making a library, you put the functions in the library, and prototypes for all the public functions in it, and 'external' definitions for all the public data in it, in a corresponding header file (usually called like the libarary but with suffix .h). The IMPORTANT part is that there should be NO actual functions NOR data declarations in the header. Anything not declared in the header will remain private to the libary. However some compilers do not like name clashes between same-named symbols located in different libraries (even if they are not public).

Then in your main program, you #include "path/to/header" and the functions are visible. The library is usually compiled separately or automatically (it's a DLL of sorts at the object file level). You must understand the semantics of the double ticks (as opposed to angled brackets) here, and apply some serious path rewriting for DOS under certain circumstances.

Now you need to tell the compiler about all the files it needs to build the executable. Sometimes you tell this the linker. In other words, pass all the required libraries (already compiled into relocatable object form) to the linker, or pass all the source file names to the compiler. I don't know what compiler you are using but sane (i.e. Unixish) compilers allow you to string everything onto the command line. DOS compilers have a limit on the command line length so they often use a command file which contains the actual list of files to use.

A tool that does almost all of this (the invocation of the toolchain parts) for you is called a make tool and YOU WANT ONE BADLY. There are free ones and there are non free ones. The 'standard' make tool is called... make. See Linux... Another make tool is a batch script of whatever shell you are using (yes, you can do it in DOS if you HAVE to).

See:


file: /Techref/language/ccpp/largeproj.htm, 3KB, , updated: 2006/4/26 21:57, local time: 2024/12/29 04:49,
TOP NEW HELP FIND: 
3.133.124.80:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/techref/language/ccpp/largeproj.htm"> The C and C++ Programming Languages </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .