Society of Robots - Robot Forum

Software => Software => Topic started by: nanob0t on May 11, 2007, 08:54:56 PM

Title: C ... I thought I'd bring the question here
Post by: nanob0t on May 11, 2007, 08:54:56 PM
Hello.  I've been in the microchip forums lately, because of a problem.  They don't know, soooo, maybe someone here can help me.   I do this on my friends computer, and it works.  I hop on my computer and do the exact same thing, exact, and I get errors.  Nothing has been configured differently.... install MPLAB, install C18, make program, build all, (insert error if at my terminal):   I'll start

I have a code.  I wanted to input the most basic stuff, so I can just run a test...  It doesn't like me... Here's the code:

Code: [Select]
#include <p18cxxx.h>

void delay (void)
{
unsigned int i;
for (i = 0; i < 10000 ; i++);
}

void main (void)
{
TRISB = 0;
while (1)
{
PORTB = 0;
delay ();
PORTB = 0x5A;
delay ();
}
}


Simple... I COPIED AND PASTED it from a beginners guide.  The program is supposed to run flawlessly.  I get a first error saying:  TRISB is an undefined character by the library... or something.  I got it once, before it got worse.  Then PORTB... Whatever.   Then the most annoying problem in the world.........


MPLINK 4.1, Linker
Copyright (c) 2006 Microchip Technology Inc.
Error - could not find definition of symbol 'FSR2L' in file 'C:\Alex's Folder\Programming\ThisProgramDoesn'tLikeToWork\main.o'.
Errors    : 1


Tell me WHERE in that code you see FSR2L???!?!?!?!?!?    It's some sample variable that by what I read in 100's of data sheets means absolutely nothing, and is completely irrelevant unless used.  And here, I guess the programmer is implying I'm using it?

I don't know.  Sorry for the lack of professionalism.  I am just fed up with it.   I've have worked through so many problems with getting this program to just WORK.  Encryption errors.  Uninstall... Reinstall.  Then I get some weird jumbled characters that doesn't let me run it.  Uninstall... Reinstall....   I don't know.


Tell me someone knows what this is.  I would pay you  :) 
Title: Re: C ... I thought I'd bring the question here
Post by: nanob0t on May 11, 2007, 09:00:21 PM
Here's some more of this:

Code: [Select]
void main (void)
{
printf ("Hello, world!\n");
while (1)
;
}

There... Probably THE most basic code, other than a blank line.  I get a funtacious error trying to run this.

MPLINK 4.1, Linker
Copyright (c) 2006 Microchip Technology Inc.
Error - could not find definition of symbol 'printf' in file 'C:\Alex's Folder\Programming\Phospholipid\main.o'.
Errors    : 1


Okay, I installed the C18 compiler...  I'm pretty sure that included the libraries.  The little box next to include the libraries is checked.  I checked it billions of times, and made sure.

Nothing............


Title: Re: C ... I thought I'd bring the question here
Post by: Liang on May 12, 2007, 03:37:55 AM
hi nanob0t,
there are two ways to print String or char[] in C.
try this:

#include <stdio.h>
void main()
{
        char t[]="Hello World!";
        printf(%s\n",t);
}


 :D
Title: Re: C ... I thought I'd bring the question here
Post by: JonHylands on May 12, 2007, 05:59:09 AM
It definitely looks like an installation issue. Just because you're not using a variable doesn't mean it doesn't get set up or used by the compiler.

FSR is the register the PIC uses for indirect memory lookup - any compiler will use that heavily. The compiler may have its own 16 bit version of that register, which is where I would guess FSR2L (and presumably FSR2H) would come from.

It sounds like you're missing a device directive. If you look in the 'include' directory of the compiler, do you see a file called 'p18cxxx.h'?

You may have to convert the 'xxx' to the actual number of the chip you are using.

- Jon
Title: Re: C ... I thought I'd bring the question here
Post by: nanob0t on May 12, 2007, 06:32:39 AM
hi nanob0t,
there are two ways to print String or char[] in C.
try this:

#include <stdio.h>
void main()
{
        char t[]="Hello World!";
        printf(%s\n",t);
}


 :D


That would work.  The problem is, the compiler says the 'printf' command is nonexistent.

It sounds like you're missing a device directive. If you look in the 'include' directory of the compiler, do you see a file called 'p18cxxx.h'?

You may have to convert the 'xxx' to the actual number of the chip you are using.

I've tried this, and it just gets me other problems.  In the first code, I tried getting rid of the microcontroller all together, and it still brings up errors. 

It looks like an installation error to me also, the problem is, I've gone through every single small bit with no success at all.  I've made sure each part in the compiler has its corresponding file.  The library has the mplib.exe file, etc.  It just makes the least bit of sense.



Thanks for the suggestions though.

Title: Re: C ... I thought I'd bring the question here
Post by: JonHylands on May 12, 2007, 06:56:07 AM
Well whether it gives you other problems or not, you have to tell the compiler what kind of chip you are using, or it will never work.

- Jon
Title: Re: C ... I thought I'd bring the question here
Post by: Admin on May 13, 2007, 07:44:09 PM
as jon said . . .

this is the first two lines of all my PIC16F877 code, should give you a hint :P

#include <16F877.h>
#include <877reg.h>
Title: Re: C ... I thought I'd bring the question here
Post by: nanob0t on May 14, 2007, 09:30:06 AM
I understand that.  I included files that are reverted to when the #include <p18cxxx.h> variable is there.  I tried inputing the same character and it gets me even more errors.  I said I tried it.  I've been program for a few months now, and I have the all of the libraries half memorized.  I know how to program with this, it's just I get some stupid error, I was wondering if anyone has ever gotten anything similar.  I tried it two ways exactly as written:

#include <p18F4431.h>
#include <p18F4431i.h>

I've tried both and I get twice as many errors.  I threw in the i incase it had something to do with the linker file names.  I get errors with every single variable in the program.  I double checked that all the libraries exist and all of them are valid, but I continue to get errors.  Then I had a programmer from Batelle look at it and he says it isn't the problem.

Eh, just scratch this post.  I'm going to use another computer.  Everything worked flawlessly until the program got some weird Encryption error and I had to reinstall.  Now it is just messed up.  I'm going to save up for a laptop.
Title: Re: C ... I thought I'd bring the question here
Post by: romangol on January 27, 2010, 02:59:30 AM
Hello.  I've been in the microchip forums lately, because of a problem.  They don't know, soooo, maybe someone here can help me.   I do this on my friends computer, and it works.  I hop on my computer and do the exact same thing, exact, and I get errors.  Nothing has been configured differently.... install MPLAB, install C18, make program, build all, (insert error if at my terminal):   I'll start

I have a code.  I wanted to input the most basic stuff, so I can just run a test...  It doesn't like me... Here's the code:

Code: [Select]
#include <p18cxxx.h>

void delay (void)
{
unsigned int i;
for (i = 0; i < 10000 ; i++);
}

void main (void)
{
TRISB = 0;
while (1)
{
PORTB = 0;
delay ();
PORTB = 0x5A;
delay ();
}
}


Simple... I COPIED AND PASTED it from a beginners guide.  The program is supposed to run flawlessly.  I get a first error saying:  TRISB is an undefined character by the library... or something.  I got it once, before it got worse.  Then PORTB... Whatever.   Then the most annoying problem in the world.........


MPLINK 4.1, Linker
Copyright (c) 2006 Microchip Technology Inc.
Error - could not find definition of symbol 'FSR2L' in file 'C:\Alex's Folder\Programming\ThisProgramDoesn'tLikeToWork\main.o'.
Errors    : 1


Tell me WHERE in that code you see FSR2L???!?!?!?!?!?    It's some sample variable that by what I read in 100's of data sheets means absolutely nothing, and is completely irrelevant unless used.  And here, I guess the programmer is implying I'm using it?

I don't know.  Sorry for the lack of professionalism.  I am just fed up with it.   I've have worked through so many problems with getting this program to just WORK.  Encryption errors.  Uninstall... Reinstall.  Then I get some weird jumbled characters that doesn't let me run it.  Uninstall... Reinstall....   I don't know.


Tell me someone knows what this is.  I would pay you  :) 

just adding /u_CRUNTIME to the linker parameters will solve your problem.
Title: Re: C ... I thought I'd bring the question here
Post by: paulstreats on January 27, 2010, 05:11:59 PM
First of all, you do definately need to identify the device. rather than using just 'xxx'.

the next part can be a bit confusing:) You need to make sure that the lib paths and stuff are set correctly (if it was a bad install, these may not have linked into MPLAB properly).
So:

1) got Project->Set Language Toolsuite
Make sure that in the drop down list that Microchip C18 toolsuite is selected.
2) click on each of the "Toolsuite contents" and make sure that they point to the corresponding filenames where you installed the C18 compiler.(in the Location box)

3)close that window and goto Project->Build Options->Project

4)Click the Directories tab then on the drop down list called "Show directories for:" Click the "Include" option then make sure that the directory is pointing to the "h" directory in your C18install directory.

choose the "lib" option from the list and make sure that it is pointing to the "lib"  directory in your C18 install directory.

choose the Linker-Script Search Path option and make sure that it points to the lkr directory in your C18 install directory.

5)Did you remember to add the devices linker script to your project?
goto Project->add files to project.
(select the .lkr filetype from below) then navigate to your C18 directory(depending on wether you have the new version or the old, you may find the lkr directory in the C18 directory or within the C18/bin/lkr) find the lr file that matches your device 18f4431_g.lkr
(if you wished you can modify your own lkr file and add that instead but you might aswell just use the standard one if you need to).

6)unless you have a Debugger selected or installed, goto Project->Build Configuration and select Release.

Hope this helps :)

(ps if you just copied a project from 1 computer to the other then it will definately need steps 3 and 4 doing as the project will be looking for files that were created from the original computers install paths)

Title: Re: C ... I thought I'd bring the question here
Post by: arixrobotics on January 31, 2010, 09:36:30 PM
Error - could not find definition of symbol 'printf' in file 'C:\Alex's Folder\Programming\Phospholipid\main.o'.

sometimes having a 'space' in the file name / directory could cause some problems too.
Title: Re: C ... I thought I'd bring the question here
Post by: Webbot on February 03, 2010, 06:04:32 AM
Error - could not find definition of symbol 'printf' in file 'C:\Alex's Folder\Programming\Phospholipid\main.o'.

sometimes having a 'space' in the file name / directory could cause some problems too.


And so can apostrophes ie ' characters