Log in

View Full Version : printf could not find definition


Alex829
25-06-2005, 22:10
Error msg:

Error - could not find definition of symbol 'printf' in file 'C:\Robot\Doomed\user_routines.o'.

before you press that reply button and tell me this question has already been answered you should know I know this already. first thing I did was search the forums. What I got was some stuff bout makings sure stdio.h was being called, make sure build options are correct, and reinstalling the compiler. I did all three of these things and nothing helps.

I am using MPLAB 7.2 if that helps any. and im just trying to get default code to compile right now. My team never really did figure out what the problem was with printf so we just commented out all the statements and moved on. I would like to use this debugging tool becuase it could save hours to know what is being outputted.

One post that I read did have me stumped and I didnt really know how it could help however the next post was the questioner saying thanks and I was left in the dark.

Do either of you still have the old compiler installed as well as the new compiler?

It seems like you are linking with an earlier version of the compiler standard library clib.lib.
That's where printf should now be coming from. Older compiler versions didn't have a printf in the library and teams used the IFI version in the project printf_lib as a substitute.

Thanks for any help you can give.

o btw if you wanna look at the the thread this came from:
http://www.chiefdelphi.com/forums/showthread.php?t=33156&highlight=printf+definition

Mark McLeod
26-06-2005, 01:23
Printf’s are worth getting running. Pardon me since I'm sure you’ve already tried these things. Some of my questions are just to reconfirm where you’re at. Also, stating the obvious might help anyone with the same problem who finds this thread through a future search.

I assume you added the call to printf in user_routines.c?

Do you have the following line defined in user_routines.c?
#include "printf_lib.h" //(only used with pre-v2.4 compilers)
or did you use
#include <stdio.h>

Do you have the include path (C:\mcc18\h) and library path (c:\mcc18\lib) specified under Project _> Build Options… -> Project

In your MPLAB project window is “printf_lib.c” or “printf_lib.h” listed (only used with pre-v2.4 compilers)?

Do you know which version of the C compiler you are running?
(Look at the first line in C:\mcc18\README.C18)

On the machine you are using did you ever install from the original CD shipped with the KOP or EDU kit? That'll beg the question: Did you uninstall all old versions of the C18 compiler before installing v2.4?

To expand on your quote from the other thread...
One of the possible causes of the problem you have occurs when you install the v2.4 C compiler on a PC that already has an older version of the compiler. The compiler is told various places and in a variety of ways where to find the files and libraries to use when compiling a project. Old and new files can get mixed. The programmer in the other post solved his or her problem by uninstalling the C18 compiler and making sure all the files were indeed gone, then installing v2.4 from scratch.

If by chance you are using an older version of the compiler, then the solution is a little different.

Ryan M.
26-06-2005, 06:56
This may or may not make a difference, but a lot of times if something isn't working right at all and I think it should, try the "clean" option. (I think that's what MPLAB calls it. If it isn't, you're looking for the build option which removes all its previous files. Alternatively, you can delete the all the compiler generated files on your own.)

Sometimes the compiler just gets confused or (more often, at least for me) you somehow manage to hit the compile button, then the save button, and the compiler gets an old version of the file, but marks the compile date on the .o as being the new file, so even a plain "build all" just results in the old file being used... :ahh:

So, try hitting "clean." It doesn't cost anything, at the least. :)

Alex829
26-06-2005, 14:38
First I would like to thank you for a detailed replay.

I looked at the version compiler version in readme.c18 and it says v2.20.
I check to see if MPLab had to correct paths in build options. Those are correct. However when I looked to see if printf_lib.h was included in my project it was no where to be found. and it I looked user_routines.c to see was included in that it said #include <stdio.h> so I dont know what that means. Maybe it means that my compiler isnt working with the default camera code? if that is the case where do I get a newer compiler version?

No other compilers have been installed on this machine. so I dont think that is the problem.

On another note I have a copy of 237s code that they posted on chief delphi to help other progrmmers. Their code has printf statements and compile fine.

Last thing is I have solved my problem a little. I can now compile with printf statements. I redownloaded the default code. I decided I dont really care about camera code and I dont really know I why I downloaded that version any way, probably b/c it is a later version so I thought eh whats the difference. However there must have been a difference b/c it compiled without a problem. so I took the files I wanted from the project I was currently working on and put them into default code project that didnt have camera code and it compiled as well. So I am guessing that the older code was made using a comiler version compatable with mine and the camera code was made using a version my compiler mine was not compatable with.

However I would still like to solve this problem so if I am right I will need to know where to get a newer version of the compiler. If that is the problem at all.

About the "clean" option. That sounds like a good idea but I couldnt find it anywhere. could you elaborate on where I can find it at? Thanks

Mike Betts
26-06-2005, 17:32
Alex,

You will find two different default codes here (http://www.ifirobotics.com/rc.shtml#Programming). One is labeled 2.2 and the other 2.4...

If your default code was referencing <stdio.h>, you were using the V2.4 and if it was referencing printf_lib.h, you were using V2.2...

From your last post it seems that you were using the V2.4 default code with the V2.2 compiler. As you found out, this will not work.

In order to get the V2.4 compiler, you must have your team's "main contact" call FIRST and request a CD. No one here can legally give you a copy.

The "clean" command is under the "project" pull down tab in the IDE.

Regards,

Mike

RbtGal1351
26-06-2005, 20:56
YAHOO!

Ok i had (i hope its past tense) the exact same problem as Alex829...

What I discovered:

- Version 2.2 compiles with the printf statements, and it includes printf_lib.h in the project

- Version 2.4 does NOT compile-- the same error message about printf definitions.
The project does not include printf_lib.h

- Version 2.4 with printf_lib.h and printf_lib.c added to the project: COMPILED!!

- My testing code that was based off of v2.4 with printf statements: Does not compile, the printf definition error message. Does not include printf_lib.h or .c

- My testing code (as above) with printf_lib.c and printf_lib.c added to the project: COMPILED!


I haven't been able to test whether the printfs actually work because i'm at home, and not at the lab with an RC.

So, in short, my (i hope) solution: Add printf_lib.c and printf_lib.h to the PROJECT. (Project -> Add files to project -> Select the file to add)

Does this solve anyone else's problems? (Or create more unexpected ones?)

:D
~Stephanie

Alex829
26-06-2005, 21:40
Thank you all who posted. all information that was given was helpful.

Mark McLeod
27-06-2005, 10:04
There was a transition this past season in the printf implementation that has caused this confusion. There are two different printf’s that can be used depending on the compiler version you are running.

When you use the older compiler, you must use the IFI printf by including printf_lib.c/.h in your projects. But the flip side of using the older compiler is you cannot use the CMU camera default code, because the camera part won’t execute correctly (however if you don’t use the camera it’ll drive fine – nothing unusual there). The project for the CMU camera version of the default code is setup to pull printf from the standard library, but as Stephanie discovered you can add the IFI printf version to the project and use that instead.
--------
Along with the two major compiler releases that concern FIRST teams there are also two major versions of the FIRST default code, v2.2(no camera) vs. v2.4(CMU camera).
The CMU camera code (v2.4) requires capabilities supplied only by the newer v2.4 compiler, and cannot be used with the older compiler. The older code can, however, be used with the newer compiler.

With the older C18 compilers (pre-v2.4) there was no printf supplied in the standard library (stdio). So for those older compilers IFI kindly wrote a printf, with some limitations, and gave it to us in those printf_lib.c and printf_lib.h files. This printf implementation is still usable, but you should read the header comments in printf_lib.c to understand the limitations. It’s the same as writing your own routine. In fact many teams modified or replaced the IFI printf code to alleviate some of the more glaring issues (buffer overwrite, space hog).

With the C18 v2.4 compiler special release to FIRST teams printf was included in the standard library, so the IFI version of printf was no longer necessary. The new version works better, but still has a few limitations you should read up on. You also need to be careful you don't inadvertently try to use both. Pick one or the other.