go_away

Author Topic: C ... I thought I'd bring the question here  (Read 6002 times)

0 Members and 1 Guest are viewing this topic.

Offline nanob0tTopic starter

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
C ... I thought I'd bring the question here
« 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  :) 

Offline nanob0tTopic starter

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
Re: C ... I thought I'd bring the question here
« Reply #1 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............



Offline Liang

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: C ... I thought I'd bring the question here
« Reply #2 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

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
Re: C ... I thought I'd bring the question here
« Reply #3 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

Offline nanob0tTopic starter

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
Re: C ... I thought I'd bring the question here
« Reply #4 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.


Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
Re: C ... I thought I'd bring the question here
« Reply #5 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

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: C ... I thought I'd bring the question here
« Reply #6 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>

Offline nanob0tTopic starter

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
Re: C ... I thought I'd bring the question here
« Reply #7 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.
« Last Edit: May 14, 2007, 09:32:06 AM by nanob0t »

Offline romangol

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Re: C ... I thought I'd bring the question here
« Reply #8 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.

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: C ... I thought I'd bring the question here
« Reply #9 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)


Offline arixrobotics

  • Full Member
  • ***
  • Posts: 119
  • Helpful? 3
Re: C ... I thought I'd bring the question here
« Reply #10 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.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: C ... I thought I'd bring the question here
« Reply #11 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
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here