View previous topic :: View next topic |
Author |
Message |
hello188
Joined: 02 Jun 2010 Posts: 74
|
linking several ".c" files? |
Posted: Mon Sep 17, 2012 7:06 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Mon Sep 17, 2012 8:02 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Sun Sep 30, 2012 11:19 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 01, 2012 3:59 pm |
|
|
I don't have the full CCS IDE so I can't do experiments to test it.
I only have the command line compilers. |
|
![](templates/subSilver/images/spacer.gif) |
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Tue Oct 02, 2012 12:46 am |
|
|
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;
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Mrinmoy Dey
Joined: 23 Jan 2018 Posts: 44
|
|
Posted: Mon Mar 13, 2023 4:05 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Mon Mar 13, 2023 5:03 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Mon Mar 13, 2023 5:15 am |
|
|
At the end of the day, if you have the source files, just remove the
extern declarations, and #include them above the main code. |
|
![](templates/subSilver/images/spacer.gif) |
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Apr 17, 2023 11:36 am |
|
|
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
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Tue Apr 18, 2023 11:41 am |
|
|
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!.... |
|
![](templates/subSilver/images/spacer.gif) |
|