Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C18: Error - could not find definition of symbol..

Status
Not open for further replies.

SiriusHardware

New Member
After several years of successfully writing moderately complex embedded programs for PIC16C series using a combination of MPLAB / Hitech C I now need to use the PIC18F452 for a project. As Hitech C doesn't support the '18' parts I have been trying to get C18/MPLAB up and running.

MPLAB C18 version: 3.42. MPLAB: V8.00

The c program is LEDS.C from within the C18 directory.

The project has been defined for the PIC18F452, which is also manually selected in configure/select device.

In the project wizard I selected the MPLAB C18 toolsuite: I added the file LEDS.C to the source part of the project, and I have added the linker file P18F452_g.lkr to the Linker part of the project. I assume that's correct so far?

When I attempt to build this project the following error occurs:

Error - could not find definition of symbol 'OpenTimer0' in file 'C:\picprojects\leds.o'.

The 'c' file includes the following lines:

#include <p18cxxx.h>
#include <timers.h>

'p18cxxx.h' references the specific definitions file 'P18f452.h'

The function 'OpenTimer0' -is- defined in the 'timers.h.' file.

The 'toolsuite locations' point to the relevant .exe files and directories in C:\Program Files\Microchip\mplabc18\v3.42\...etc.

I can't understand why, when the processor type has already been specified in the project wizard, everything else (linker file, header file, etc) isn't set up automatically. Isn't that what a Wizard is for?

Following one suggestion, I tried adding 'p18f452.lib' to the 'libs' section of the project. This simply led to it being unable to find a different definition ('STATUS'). I've removed 'p18f452.lib from the project again, so the situation is as outlined above.

Looking around the net I see variations on this question repeated over and over again, always seemingly with a different answer. It suggests that there is something fundamentally wrong with this compiler.

How do I go about getting this program to compile?
 
Last edited:
Could you please post the code (or a link to the code on, say, https://www.pastebin.com? Generally I've noticed that function names don't start with a capital. OpenTimer0, for example, is probably actually openTimer0. I really need to see your code. I don't think I can help you much without it.
 
Last edited by a moderator:
Generally I've noticed that function names don't start with a capital. OpenTimer0, for example, is probably actually openTimer0.
DS... It does in this case OpenTimer0(); is correct .

Most frequent errors are using 'O' oh... when it should be '0' zero....
 
DS... It does in this case OpenTimer0(); is correct .

Okay, thanks for letting me know :)

P.S. New thought: Did the OP remember the parentheses after "OpenTimer0"? That's another common mistake I see.
 
Last edited:
Hello, both: Thanks for responding to my query - it's very late just now and I don't have time to dig up the code and post it, but in any case I may not need to, as you should have copies of it accessable to you on any installed copy of C18 - it isn't code that I wrote - it's demo code provided by Micropchip as part of the C18 installation.

Ian is correct in stating that the definition of OpenTimer0 in timers.h is with a capital 'O' as the first letter.

DS, if there is an 'Oh' present in leds.c instead of a zero, I did not put it there - the file leds.c is a demo code file taken from (on my installation)

C:\Program Files\Microchip\mplabc18\v3.42\example\users_guide\example1\leds.c

I chose it because it happens to be an example written for the very processor I am interested in.

I didn't include the parenthesis in the details above because the failure message only stated the name of the symbol / function / whatever it could not find the definition of - however leds.c and timers.h both 'know' it is a function and refer to it as such, with parenthesis after the name.

If you still need me to post the the code, let me know, but in the meantime anyone can try to replicate my problem by using the project wizard to make a project for PIC18F452 / C18 Toolsuite with the above mentioned 'C' source file and presumably also the LKR file p18F452_g.lkr - I understand (perhaps incorrectly) that one 'c' source file and one device-appropriate .lkr file should be the only elements the project needs in order to compile without errors.
 
I have just created a project.. called "proj" and copied and pasted the Leds.c into the project, saved, built and no errors..

Have you added to "leds.c" file from its current position, or have you copied the file to the new directory?
 
I have just created a project.. called "proj" and copied and pasted the Leds.c into the project, saved, built and no errors..

Have you added to "leds.c" file from its current position, or have you copied the file to the new directory?

Hello Ian,

From what you say it sounds like you didn't even need to add a linker file into the project, or maybe you just automatically did? If I remove P18F452.lkr from the project it gets even less far - complains that there is no linker script and halts.

Just checked and I think I've navigated to and added leds.c into the project from its orginal location. There isn't a 'new' directory as such, because I always create new projects in C:\picprojects - doing that has never caused problems with either MPLAB assembly language projects or MPLAB / Hitech C projects. (There is no other project or .c file called 'leds' in that directory).

I'll try moving leds.c to the project directory and adding it to the project from there.

Thanks for taking the time to consider the problem.
 
From what you say it sounds like you didn't even need to add a linker file into the project, or maybe you just automatically did? If I remove P18F452.lkr from the project it gets even less far - complains that there is no linker script and halts.

NEVER had this problem.... I only link a LKR script when I need to modify the original.... (copy the original and paste into the working directory)

It appears that your project directories are not set up correctly.... The default LKR script IS, as you say, automatically included... I would look at the projects directory settings and (in particular) look at the "intermediate" and "include" paths... These need to be the defaults... If you have these as your working directory... The project linker will not find the files.
 
The newer versions of MPLAB have the linker built in, so you don't have to add any files. It'll take care of it all for you. I think the latest version is 8.86. What version do you have?

Also, i'm not seeing where you added any header files (xxx.h). That is where all the definitions are. I see you typed it into the code, but in the project wizard, where it asks to add files, you ought to have chosen the header files and added them to the project. Just typing it in the code won't work.

EDIT: Just re-read your first post, so I see you have v 8.00. That is very old. I suggest you back up your programs and do an upgrade.
 
Last edited:
Hello again, Ian, DS, thanks for your continuing comments.

DS- I must stress again that I have (so far) not written any code myself. I'm using code supplied by Microchip as part of the C18 installation. The aim here is simply to get MPLAB 8.00 and C18 V3.42 working together for the first time. These versions are contemporary, that is to say, they were supplied on the same disc (which came with my PICKIT2). I would be amazed if they can not be made to work together.

As to why I'm using MPLAB V8.00 (apart from the fact that it is simply what I already have, and has served me perfectly well until now) it runs moderately well on the old Windows 98 machine which is the only computer conveniently available to me at work, and so I continue to use the same version here at home as well, so I don't get any issues with the older version of MPLAB at work not being able to work with projects written on a newer version somewhere else. It means I can freely port port projects back and forth between work and home. A later version of MPLAB (V8.66) was tried on the '98 machine - it could barely run it, so I took it back to 8.00, which runs well in that environment.

The leds.c file I referred to earlier -

c:\program files\microchip\mplabc18\V3.42\example\users_guide\example1\leds.c

has #include lines for a generic 18x452 header ((P18Cxxx.h) which in turn references the specific header file P18F452), and for timers.h, which contains the definitions of the timer functions used in leds.c. You can examine this file yourself, if you look in the above mentioned folder (the path to your installation may be a little different of course).

When creating the project in the MPLAB project wizard, I select the C18 Toolsuite. The toolsuite executable locations are set up as follows:

Assembler
C:\program files\microchip\mplabc18\V3.42\bin\mpasmwin.exe
Compiler
C:\Program Files\Microchip\mplabc18\v3.42\bin\mcc18.exe
Librarian
C:\Program Files\Microchip\mplabc18\v3.42\bin\mplib.exe
Linker
C:\Program Files\Microchip\mplabc18\v3.42\bin\mplink.exe

Search paths and directories:-

Output
C:\picprojects
Intermediate
C:\picprojects
Includes
C:\Program Files\Microchip\mplabc18\v3.42\h
Library
C:\Program Files\Microchip\mplabc18\v3.42\lib
LinkerScripts
C:\Program Files\Microchip\mplabc18\v3.42\bin\LKR

The project (as mentioned earlier) is always created in C:\Picprojects.

Following specific instructions given in the 'getting started with C18' .htm file also included with my versions, I invoke the project wizard, choose the processor (PIC18F452), choose the toolsuite (C18), specify the name of my project and its location, and finally add my already prepared .c file to the 'source' portion of the project and P18F452_g.lkr to the 'linker scripts' portion of the project.

Following earlier comments here I scrapped everything and made a new project, this time with leds.c already placed in c:\Picprojects, and added it into the project from there. Unfortunately I still get the same result upon trying to build, which is this:

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\picprojects\leds.o".
Clean: Deleted file "C:\picprojects\C18_test_2.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\mplabc18\v3.42\bin\mcc18.exe" -p=18F452 /i"C:\Program Files\Microchip\mplabc18\v3.42\h" "C:\Program Files\Microchip\mplabc18\v3.42\example\users_guide\example1\leds.c" -fo="leds.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\Program Files\Microchip\mplabc18\v3.42\bin\mplink.exe" /l"C:\Program Files\Microchip\mplabc18\v3.42\lib" /k"C:\Program Files\Microchip\mplabc18\v3.42\bin\LKR" "C:\Program Files\Microchip\mplabc18\v3.42\bin\LKR\18c452_g.lkr" "C:\picprojects\leds.o" /o"C18_test_2.cof" /M"C18_test_2.map" /W /p18f452
MPLINK 4.43, Linker
Device Database Version 1.8
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - could not find definition of symbol 'OpenTimer0' in file 'C:\picprojects\leds.o'.
Errors : 1

Link step failed.
BUILD FAILED: Mon Jul 02 19:48:51 2012

(Note that this editor has wrapped some of the longer lines around to fit them into this message width).

MM, just noticed, the above build attempt was made with the 'source' segment of the project still pointing at the version of leds.c in its original location within the install directory. But it fails with the same error even if I remove that .c file and then add the version of leds.c which is in c:\picprojects to the project instead.
 
Last edited:
Mods, please remove this message - I've incorporated what I originally wrote here into the body pf the previous message (how do I delete a post?)
 
Last edited:
Mods, please remove this message - I've incorporated what I originally wrote here into the body pf the previous message (how do I delete a post?)

Just click edit it and type "post removed" :D
 
DS- I must stress again that I have (so far) not written any code myself. I'm using code supplied by Microchip as part of the C18 installation.

Ah yes, I'm sorry. I should have worded it differently.

I meant that including the header file in the code does not actually add it to the project. To do that, you need to add the .h in the project wizard. I have a feeling that might be part (if not all) of your problem.

As to why I'm using MPLAB V8.00 (apart from the fact that it is simply what I already have, and has served me perfectly well until now) it runs moderately well on the old Windows 98 machine which is the only computer conveniently available to me at work, and so I continue to use the same version here at home as well, so I don't get any issues with the older version of MPLAB at work not being able to work with projects written on a newer version somewhere else.

Okay, that makes sense. I don't think you had mentioned that before, which is why I suggested upgrading.
 
NEVER had this problem.... I only link a LKR script when I need to modify the original.... (copy the original and paste into the working directory)

It appears that your project directories are not set up correctly.... The default LKR script IS, as you say, automatically included... I would look at the projects directory settings and (in particular) look at the "intermediate" and "include" paths... These need to be the defaults... If you have these as your working directory... The project linker will not find the files.

As you can see from my other recent post I've got the includes (.h) and linker scripts (.lkr) set up to where they definitely are, but the 'intermediate' set to the project directory - I thought this would be OK since the name suggests that this folder is just used for files temporarily created during the compilation/linking process. What IS the default setting for the "intermediate" directory? (what does yours say?)
 
I meant that including the header file in the code does not actually add it to the project. To do that, you need to add the .h in the project wizard. I have a feeling that might be part (if not all) of your problem.

That's at odds with my understanding of how things normally work, but then again this is Microchip, so define normal ;)

Seriously though: If the .c source contains the line '#include timers.h>' and the toolsuite location definitions state that the includes directory is:

C:\Program Files\Microchip\mplabc18\v3.42\h

-isn't that combination enough for the compiler / linker to be able to find timers.h in that folder?

In any case I think your thought occurred to me too, and I tried explicitly adding timers.h to the project as well - exactly the same result, so I took it out again. (I've just tried it again, to be sure).
 
That's at odds with my understanding of how things normally work, but then again this is Microchip, so define normal ;)

Seriously though: If the .c source contains the line '#include timers.h>' and the toolsuite location definitions state that the includes directory is:

C:\Program Files\Microchip\mplabc18\v3.42\h

-isn't that combination enough for the compiler / linker to be able to find timers.h in that folder?

In any case I think your thought occurred to me too, and I tried explicitly adding timers.h to the project as well - exactly the same result, so I took it out again. (I've just tried it again, to be sure).

It is not always enough. I have a much newer version of MPLAB, so things might be different, but did you try adding the header files through the project wizard, or did you do it manually in the project window? If v.8.00 isn't too much different from 8.76 (what I have), there should be a window with a bunch of folders in it. Is this where you added the .h files (directly to the "header files" folder)?
 
It is not always enough. I have a much newer version of MPLAB, so things might be different, but did you try adding the header files through the project wizard, or did you do it manually in the project window? If v.8.00 isn't too much different from 8.76 (what I have), there should be a window with a bunch of folders in it. Is this where you added the .h files (directly to the "header files" folder)?

Yes, that's where I did it. The steps to add timers.h to the project were (with the project loaded)

>View
>Project (This displays the project tree, (Source files, Header Files, Object Files, Library Files, Linker Script, Other Files))

Right-clicking on 'header files' in that tree brings up a small window with 'filter' and 'add files' as the choices.
Choosing 'add files' gets me a file browser which I use to make my way to

'C:\Program Files\Microchip\mplabc18\v3.42\h\timers.h'

which, when selected, is then shown to have been added to the 'header files' part of the tree. But if I then do a 'build all', the result is exactly the same - a fail, same message. It makes no difference whether it's in there or not.
 
As you can see from my other recent post I've got the includes (.h) and linker scripts (.lkr) set up to where they definitely are, but the 'intermediate' set to the project directory - I thought this would be OK since the name suggests that this folder is just used for files temporarily created during the compilation/linking process. What IS the default setting for the "intermediate" directory? (what does yours say?)

Nothing.... Its all blank, If you leave it blank it defaults to... A) the working directory of the project.. and B) The path determined by the installer program when C18 was installed..

What did you install first... MPLAB or C18?

You may want to install the latest MPLAB ( Its getting large now ) I use version 8.83... I think the very latest is 8.86.....

When I installed a new version of MPLAB, it couldn't find C18 as it was installed in a different directory than MPLAB expected .....(AARGH)!!

It thought I had C18 version 3.39 (which used to be in "C/mcc18/v3_39" ).... But it was actually in "C/Program files/Microchip/mplabc18/v3_40"...
All because I installed them the wrong way round.... ( sorted it now )

It just goes to show you can't take anything at face value.....

You need to check the Toolsuite settings.. Just make sure they are right.
 
Nothing.... Its all blank, If you leave it blank it defaults to... A) the working directory of the project.. and B) The path determined by the installer program when C18 was installed..

What did you install first... MPLAB or C18?

It just goes to show you can't take anything at face value.....

You need to check the Toolsuite settings.. Just make sure they are right.

The default install for MPLAB also helpfully installed C18 at the same time.

I think my 'Intermediate' path was originally set to BLANK, but because it wasn't working I tried changing it to something else. (I do remember thinking 'That's insane - if it doesn't tell me what the default setting is, how am I supposed to know whether the default setting it has chosen is right?).

It's now set to the project directory, which it seems ought to be OK, according to your info above.

As to whether the rest are correct, the paths listed in my post #10 in this thread were individually cut and pasted from the boxes in the actual C18 toolsuite settings in MPLAB - so what you see posted in that message is exactly how those parameters in the C18 toolsuite are currently set.
 
Status
Not open for further replies.

Latest threads

Back
Top