Search this site (www.microchipC.com).





CCS C Compiler for Microchip PIC micros

Your ad here

  Different methods setting up Projects under Hi-Tech C and MPLab (advanced topic)

When it comes to compiling files under Hi-Tech C, there are two methods of doing it. One method is to have a single main.c file, and use #include for all the .c files in the project. Call this the 'one file with multiple #include of c files' method.

The second method, also the one usually recommended by C programmers, is to have lots of individual .obj files, and link them at the end. Call this the 'lots of .obj files' method.

For the 'one giant file' method, in MPLab under 'node properties', select 'PIC C compiler' for the root node. For the 'lots of .obj files' method, select 'PIC C linker' for the root node.

The advantages of the 'one file with multiple #include of c files' method

Produces smaller .hex file for a large compiled program. For the 16F876/7, there is 8k of program, divided into 4 pages. A psect cannot cross a page boundary. Sometimes there is wasted space before the end of each page boundary. Because the linker has access to all the functions at once, it does a really good job of fitting them in. Try it yourself - get a large (~8k, ~5000 line) program, and it will be smaller using this method.

The advantages of the 'lots of .obj files' method

  • This method supports libraries (ie: in MPLab under 'Edit Project, the 'library path' box is enabled.
  • This method supports incremental compiles, which saves a little time, as long as the correct path is entered

What do you think? email support@microchipc.com.

-----Original Message-----
From: Graham Harrison [mailto:<snipped>]
Sent: Thursday, 15 February 2001 9:59 p.m.
To: support@microchipc.com
Subject: one giant file

Shane

I sometimes use an ICEPIC Jnr for debugging, and I've noticed that single stepping doesn't seem to work across files which have been linked, but works fine within the main() loop.

Graham

-----Original Message-----
From: Ivan Cenov [mailto:okto7@botev.ttm.bg]
Sent: Thursday, 29 March 2001 2:26 a.m.
To: support@microchipc.com
Subject: one giant file

Shane,

I think that one giant file should be used when there is space problems only. I prefer 'lots of obj files' method. This makes my life easier. I can distribute my functions in different files depending on their purpose. And if something is lost, the rest is still available.

There is a third method between 'giant file' and 'lots of obj files': One main file which #includes lots of source files. This method serves good input to the linker while the programmer still has the opportunity to divide source code by the purpose.

But there is no good things without bad things. Try to simulate that code in MPLAB. MPLAB does not want to switch to the included sources. It traces only main #including file.

Ivan Cenov



This site is non-profit. Ad revenue almost covers hosting costs.

We welcome any suggesions or comments! Send them to Shane Tolmie on support@microchipc.com. This site is a completely separate site to www.microchip.com, and is maintained independently of Microchip Ltd., manufacturers of the PIC micro. All code on this site is free for non-commercial use, unless stated otherwise. Commercial use normally free, however, it is prohibited without contacting support@microchipc.com for permission. All content on this site created by Shane Tolmie is copyrighted by Shane Tolmie 1999-2009. Click to advertise on this website - $29.90 for a banner ad which will reach 55,000 user sessions per month. One months free trial!