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

Newbie main() error problem

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







Newbie main() error problem
PostPosted: Tue Jan 30, 2007 11:31 am     Reply with quote

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: 1907

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 11:43 am     Reply with quote

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







PostPosted: Tue Jan 30, 2007 12:11 pm     Reply with quote

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: 1907

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 12:15 pm     Reply with quote

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







PostPosted: Tue Jan 30, 2007 1:44 pm     Reply with quote

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: 1907

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 1:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 1:59 pm     Reply with quote

See my post in this thread which shows how to organize the main
source file:
http://www.ccsinfo.com/forum/viewtopic.php?t=18649

See my first post in this thread, which shows how the Project Window
in MPLAB should look:
http://www.ccsinfo.com/forum/viewtopic.php?t=27115

See this thread for info on how to add the additional source files
to the "Other Files" section in the MPLAB Project Window:
http://www.ccsinfo.com/forum/viewtopic.php?t=25826
jabackma
Guest







PostPosted: Tue Jan 30, 2007 2:50 pm     Reply with quote

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!
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