View previous topic :: View next topic |
Author |
Message |
jabackma Guest
|
Newbie main() error problem |
Posted: Tue Jan 30, 2007 11:31 am |
|
|
Hi, All,
I am brand new to this compiler, and created a project with three files, one of which has a main() in it. When I try to compile, I get a
No MAIN() function found
error, as the first file it compiles is not main.c - main.c is the middle of the three Source Files listed, but that should not matter I think. I can rightclick compile main.c fine though.
So my question is: why is it insisting that it needs a main() just to compile one of the other c files? It should whine about main() not existing at link time.
John |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Tue Jan 30, 2007 11:43 am |
|
|
Even though CCS has trumpeted how their new version 4 has a linker, many people have found that the linker either doesn't work or doesn't work properly.
If you're using version 3 (even if you're using version 4), you have to compile ONE big file. All files must be #include(d) in the primary file - the one that you ultimately compile. This primary file is the one with the main() function. |
|
|
jabackma Guest
|
|
Posted: Tue Jan 30, 2007 12:11 pm |
|
|
Thanks for the quick reply.
This is a brand new, shiny just off the lot compiler for the 16F parts.
So what you are saying is I can only have one .c file? That seems odd... when I did the Project Wizard it let me add all the Source C Files I wanted.
So have one source file, say main.c in Source Files, then
#include "file1.c"
#include "file2.c"
etc at the beginning of it? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Tue Jan 30, 2007 12:15 pm |
|
|
Right. If you name your project "test", the wizard will create test.c and test.h files. The first line of test.c will be #include "C:\whatever\test.h". DO NOT include other .c files ABOVE this line......that's a big no-no.
#include as many .c files after this that you wish, but before the main(). |
|
|
jabackma Guest
|
|
Posted: Tue Jan 30, 2007 1:44 pm |
|
|
Actually, my MPLAB 7.5 does not create any files.
I tried throwing all my simple files in one file, along with main() and it compiled! So that is one solution.
If I try to take baby steps towards multifile, lets say I have a file
"led_display.c"
#include "led_display.h" //line one of the file
#include "switch.c"
...
and in "led_display.h"
#include <16F917.h>
I then get a compile error on :
-Can not change device type this far into the code
which is stupid because the error points to the first line of 16f917.h
//////// Standard Header file for the PIC16F917 device ////////////////
#device PIC16F917 <this>
#nolist
Maybe I just need a good example of a multi file C project in the public domain that works. I note that all the demo files are standalone one C file apps. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Tue Jan 30, 2007 1:51 pm |
|
|
Here's an example of a typical .h file generated by the CCS wizard:
Code: | #include <18F452.h>
#device adc=8
#use delay(clock=4000000,RESTART_WDT)
#fuses XT, BROWNOUT, BORV20, PUT, STVREN, NOLVP
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
I was assuming that you were using the CCS project wizard - didn't know you were actually using MPLAB.
Anyway, the "can't change device this far into code" usually pops up if there are multiple #include <processor.h>'s. It can also pop up if this particular include is not the very first line in your program with no spaces or anything else in front of it. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
jabackma Guest
|
|
Posted: Tue Jan 30, 2007 2:50 pm |
|
|
Thanks, guys, I now have it working with more than one C file.
Man, that was more difficult then in the Atmel or TIDSP world! |
|
|
|