Newbie Error Function Main Not Defined

General discussion on mikroC.
Post Reply
Author
Message
cmoher3
Posts: 24
Joined: 26 Jul 2008 07:39

Newbie Error Function Main Not Defined

#1 Post by cmoher3 » 26 Jul 2008 07:45

Greetings. I'm working from Dohan Ibrahim's Advanced Microcontrollers book. My first program is exactly this:
void main()
{
unsigned int Sum, i;
TRISC=0

Sum=0;
For (i=1; i<=10; i++)
{
Sum = Sum + i;
}

PORTC=Sum;
}

When I build this, I get a Function Main Not Defined error. It's been decades since I wrote anything in C. I don't recall ever having to define the Main function. I am using the free limited edition of MikroC. Your help is greatly appreciated in advance.

pwdixon
Posts: 1431
Joined: 13 Apr 2005 11:14
Location: UK

#2 Post by pwdixon » 26 Jul 2008 08:43

you are missing a ; after trisc.

But this simple app has also revealed something I'd never thought about before. Even adding the ; gives and error on the 'For' it appears that MC does like the capital F, change to 'for' and it compiles ok.

I tried a 'While()' and that objects as well, not checked any other commands (yet).

cmoher3
Posts: 24
Joined: 26 Jul 2008 07:39

Thank you but error persists

#3 Post by cmoher3 » 26 Jul 2008 11:40

Thanks very much. I'm embarrassed by my oversight....it's 3 AM when I did this. Unfortunately, I changed the code as follows and I still get the same error:

void main()
{
unsigned int Sum, i;
TRISC = 0;

Sum = 0;
for (i=1; i<=10; i++)
{
Sum = Sum + i;
}

PORTC = Sum;
}
Is this MikroC pretty picky about column positions perhaps ??

Mike Brearley
Posts: 173
Joined: 09 Apr 2008 12:56

#4 Post by Mike Brearley » 26 Jul 2008 12:18

Hello There
I don't know what you are doing wrong as I have just compiled your code with no trouble. The thing you have not said is which pic you ate compiling for. I used 16F887
Mike

cmoher3
Posts: 24
Joined: 26 Jul 2008 07:39

#5 Post by cmoher3 » 27 Jul 2008 01:20

I started from scratch and everything works fine now, although I don't know what I was doing wrong in the first instance. Thanks

jbrookley
Posts: 12
Joined: 28 Jul 2008 20:04
Location: Ventura, CA

#6 Post by jbrookley » 28 Jul 2008 20:06

For the record, you'll see that error if you try and build a C file without creating/saving a project file. That's why starting all over worked out for you. If you get that error again, just go to Save Project As, etc and it should work.

How do I know this? Cuz I had that same problem and it took me far longer to figure out the problem than it should have . . .

idakota
Posts: 334
Joined: 27 Sep 2006 08:07
Location: Pretoria/South Africa
Contact:

#7 Post by idakota » 28 Jul 2008 21:21

pwdixon wrote:you are missing a ; after trisc.

But this simple app has also revealed something I'd never thought about before. Even adding the ; gives and error on the 'For' it appears that MC does like the capital F, change to 'for' and it compiles ok.

I tried a 'While()' and that objects as well, not checked any other commands (yet).
Thats probably due to ANSI Cs case sensitivity :)

hazad
Posts: 77
Joined: 13 Oct 2009 02:22
Location: BELEK/ANTALYA

Re: Newbie Error Function Main Not Defined

#8 Post by hazad » 12 May 2011 16:22

So I have the same error. Still Searching for this problem. I will write if I found. Thanks a lot

vishaletm
Posts: 50
Joined: 26 Jan 2012 05:09
Contact:

Re: Newbie Error Function Main Not Defined

#9 Post by vishaletm » 26 Jan 2012 05:13

I am also having the same problem FOR THE EXAMPLE MANCHESTER CODE given in help. I just copy and paste the code and compile! Error is "main function not defined" please help me i am in middle of a project
http://microcontrollerprojects00.blogspot.com/
ARM, PIC , AVR, 8051 Projects/Tutorials (MikroC)
If you get, give. If you learn, teach.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Newbie Error Function Main Not Defined

#10 Post by filip » 26 Jan 2012 09:51

Hi,

Most likely you didn't include the source file where you pasted your code into the project that you are trying to compile.
Please, use Project Manager and add the source file and it should compile OK.

Regards,
Filip.

Post Reply

Return to “mikroC General”