CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

linking several ".c" files?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

linking several ".c" files?
PostPosted: Mon Sep 17, 2012 7:06 am     Reply with quote

Hi. I am trying to transport a source code that consists of 3 .c files.

main.c file, links functions made in the other two .c files by using "extern" key-word.

I am running the CCS compiler(4.127 PCH) on MPLAB IDE.

It looks like the compiler is compiling the three source file sequentially. After that, the compiler freezes momentarily and the compile option in the MPLAB IDE becomes no longer available.

Can CCS-C compiler link multiple .c files together??

Thank you
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 8:02 am     Reply with quote

CCS C can do multiple compilation units... sort of. It doesn't have a linker, but the CCS IDE emulates this sort of behaviour through the way it organises projects. I've not heard good things about this feature, and I've not heard of anyone reporting much success with it, so I cannot advise if it'll work for you. This though is done at project level via the CCS IDE, and I doubt it works when using MPLAB as an IDE, which has its own idea of projects.

In any case, simply importing C code and expecting it to work unmodified is a route to almost certain disappointment. That though is true to some extent to all C compilers, but especially CCS C, for a number of reasons, mostly related to hardware peculiarities and limitations. So you're going to have to expend significant effort to get that code to work.

RF Developer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 12:20 pm     Reply with quote

See near the end of this thread. It shows you can use Mulitple Compilation
Units with MPLAB, provided that you have the full IDE version of CCS
(such as PCWH, PCWHD, etc.):
http://www.ccsinfo.com/forum/viewtopic.php?t=38254

This thread has some help for Multiple compilation units:
http://www.ccsinfo.com/forum/viewtopic.php?t=42402

These threads are about compiling multiple files by using #include
statements (and not using Multiple Compilation Units):
http://www.ccsinfo.com/forum/viewtopic.php?p=110805
http://www.ccsinfo.com/forum/viewtopic.php?t=32221
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 11:19 pm     Reply with quote

Thank you for your reply, PCM Programmer

Now, I understand that, I need the PCWHD IDE from CCS to be able to link multiple object image made from multiple .c source files.

When I first started using PIC, I purchased the full PCWHD(The fullest Possible version(including PCB, PCH, PCM, PDWH, PDWHD, etc...), at 4.099 Version) around 2009.

As Microchip added new devices, I had to update my compiler as well. Seeking the lowest cost option, I only purchased update for PCM and PCH, as our project only used 16 and 18 series MCU's.

However, bottom line is, that I did purchase the full IDE, at one point, so I
have it available with me.

Can I make the MPLAB IDE use CCS IDE to link the multiple compilation units??

Thank you for your support PCM Programmer.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 01, 2012 3:59 pm     Reply with quote

I don't have the full CCS IDE so I can't do experiments to test it.
I only have the command line compilers.
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 12:46 am     Reply with quote

I tried simple program with 2 .c file


It compiles well when I selected CCS compiler as my project's tool suite. Both in MPLAB IDE 8.87 and MPLAB IDE X

It gives me the correct result when I look at the value of the variable using the watch window in debug mode using MPLAB Simulator.

So, it should work fine, when I build it in release mode and program on the real chip?

Would it not have worked if I didn't have full IDE with me in the tool suit??

I'm confused?

The bottom line is that it compiles well and works well using simulator.

Thank you.

Code:
//common.h
#include <18F23K22.h>
#fuses HSM, NOPUT
#include <stdint.h>



Code:
//main.c
#include "common.h"


extern uint8_t myAdder(uint8_t input1, uint8_t input2);

uint8_t hello1 = 8;
uint8_t hello2 = 19;
uint8_t result = 0;
void main(void){
   result = myAdder(hello1, hello2);
   while(1);
}   



Code:
//myAdder.c
uint8_t myAdder(uint8_t input1, uint8_t input2){
   
   return input1 * input2;
}
Mrinmoy Dey



Joined: 23 Jan 2018
Posts: 44

View user's profile Send private message

PostPosted: Mon Mar 13, 2023 4:05 am     Reply with quote

Is there any update on this problem now?
Can we use multiple .c file using MPLAB X IDE and CCS compiler combination?

I am stuck in a problem of external interrupt detection with above combination.

Thanks in Advance.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 13, 2023 5:03 am     Reply with quote

hmmmm, You've 'tagged onto' a 10 year old post..
Really, begin your own post with a small example of your code and your problem
Historically the compiler didn't work well with MCUs. Frankly I've yet to see one example where MCU is a better method of programming PICs, showing any advantage .
I've only used them for 2+ decades, so maybe I've missed the post that shows the benefit to MCUs.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Mar 13, 2023 5:15 am     Reply with quote

At the end of the day, if you have the source files, just remove the
extern declarations, and #include them above the main code.
allenhuffman



Joined: 17 Jun 2019
Posts: 554
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 17, 2023 11:36 am     Reply with quote

We have encountered many issues over the past few years, which forum responses said "multi-unit compilation has problems." Because of that, I finally updated all our projects to #include the .c file in main. The binaries got smaller, for some reason!

I added the same #ifdef escapes I use for header files:

Code:
#ifndef FILE_C
#define FILE_C

// Includes
// main.h, compiler headers, this file header, other headers, common headers.

// Constants

// Variables

// Typedefs

// Prototypes

// ISRs

// Functions

#endif /* FILE_C */

// End of Filename.c


And inside main I have a block of #includes before main().

It's been working very well with none of the strangeness I've battled for the past few years Smile

But, other developers frown on this so I had to leave in comments...

Code:
// Multi-Unit Compilation seems to have problems. This is the recommend way to
// build with CCS.
// Incuding ISR.c at the top to work like original that had them before main.
#include "ISR.c" // include as first .c file.
#include "ADS1015.c"
#include "Attenuator.c"
#include "ControlCommands.c"
#include "ControlConfig.c"
#include "ControlMessages.c"
#include "ControlUtils.c"
...

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue Apr 18, 2023 11:41 am     Reply with quote

Getting smaller is inherent.
Basically common code will only be included once, and the compiler
can optimise the shared stuuf better.
You can now see one advantage!....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group