CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Function used but not defined
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
TTM



Joined: 08 Feb 2022
Posts: 7
Location: France

View user's profile Send private message

Function used but not defined
PostPosted: Tue Feb 08, 2022 5:29 am     Reply with quote

Hello there,

I'm using Linux version of PCM Compiler Ver. 5.105

Each time I'm trying to use some specific function of the PCM compiler, like input_b(), set_tris_a() etc, the linker says :

Error#112 Function used but not defined: ... input_b

I'm running the compiler through the MPLABX environment, but even on the command line, the command:

./ccsc +fm examples/ex_pbutt.c

Returns the same error. I couldn't find anything on the net ...

Thanks in advance

TTM
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 6:52 am     Reply with quote

the error msg means the 'order' of the functions and main() is wrong.
main() is trying to use a function, yet is doesn't exist.

curious was I..
I created a project, with ex_butt as the file.
used PIC18F46K22 as the PIC( my deault)
F10 to compile...
successful !!
I do use MPLAB8v92 not MPLABX
Also older version of compiler, mid 4000 ish

hopefully someone with your compiler version and MPLABX will respond soon.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 7:16 am     Reply with quote

Probably the file layout in the IDE.
Remember with MPLAB, you should _only_ put the actual main C file in
the 'source files' tab. Everything else should ideally not go into any
tab at all (and just be #included in the main file). MPLAB tries to compile
separately every file that is in the source files tab. This is a classic fault
for trying to compile files that are not designed to be compiled separately.

pbutt assumes it is being compiled from one compiler. If you have a
license that supports multiple compilers (so PCB/PCM/PCH), you need
to force it to the chip family you want to use by specifying which of the
compilers is to be used. +FB, +FM or +FH. Otherwise it won't work.

I must admit I'd have expected your command line to work. It does for me.

I realise it is dependant on the PATH variable correctly locating the
include files and DLL's for the processor involved. It won't compile
unless this is the case.
TTM



Joined: 08 Feb 2022
Posts: 7
Location: France

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 2:10 pm     Reply with quote

temtronic wrote:
the error msg means the 'order' of the functions and main() is wrong.
main() is trying to use a function, yet is doesn't exist.
.


Thanks temtronic,

I don't think the "order" is the issue (despite I already read something like this somewhere on the net, but this was not the issue)

In C, (or most compiled languages) you compile first, and then you link.
If the function prototype is defined somewhere (which is the case in the device .h file), the compile process will run ok.
It's during the linking that the tool will fetch the library's code you're calling (here, input_b) and place it in the final hex file
And here, the issue is that the code for that part of library doesn't exist

So, I tried to reinstall everything (I was having both PCB and PCM at the same location and was thinking that could be the issue); then I tried the following:



./ccsc +fm examples/ex_led.c

But I still get the same error:


PCM Compiler Version 5.105
xxxxxx yyyyyyyyy
/opt/picc/pcm/examples/ex_led
1 Errors, 0 Warnings, Build Failed., Time: 1 Seconds
Error[112] /opt/picc/pcm/examples/ex_led.c 83 : Function used but not defined: ... set_tris_b 126 SCR=894
Build Failed.
TTM



Joined: 08 Feb 2022
Posts: 7
Location: France

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 2:15 pm     Reply with quote

Ttelmah wrote:

I realise it is dependant on the PATH variable correctly locating the
include files and DLL's for the processor involved. It won't compile
unless this is the case.


Thanks Ttelmah for your reply,

So, I already explained to temtronic that I don't think the issue is with the source code itself.

I'm using the Linux version, and the way I'm calling it is as below:

./ccsc +fm examples/ex_led.c

So, I do specify the right compiler to use. But I still get the same issue
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 2:41 pm     Reply with quote

Using the ex_butt.c program, you'll notice the functions are coded BEFORE main(). Done this way it will compile fine. Did for me,anyway
...
function1()
function2()
main()
...

if you try

main()
function1()
functio2()

you'll get the error

UNLESS you type blank 'prototypes' before main()

Least that's what I was led to believe. Never had a 'C' course and CCS is the only C I've used. I've followed CCS's examples and they work....

I assume this is how the compiler operates but haven't any idea why it fails for you, though I suspect MPLABX ?

Someone running that will know
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 5:26 pm     Reply with quote

It's acting like it doesn't see the header file for the PIC. I would try making a local copy of the example file, and in that local copy remove the #if/elsif stuff that sets the header file, and then just manually include a header file for that chip. See if it compiles then. If it does, then you may need to call your command specifying one of the #define values the original version.

One other thing. version 5.105 does have a few parsing bugs in the compiler, so it could be related. Might be worth sending an email to CCS support if you can find a solution. I had to for my problems and they sent me a fixed DLL.

Alternately you can try an earlier version. I know that 5.087 and 5.093 doesn't have those same parsing bugs. I haven't tried other versions.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 7:45 pm     Reply with quote

OK, I took ex_pbutt.c, copied, renamed,edited to move the function 'clear_delta()' AFTER main().

It FAILED to compile.. 'undefined identifier.. ' error message

This, to me, confirms that functions MUST be coded before main() or at least before they are used. A function could be called from another function.

So it's still a mystery to me why the original ex_pbutt failed for you.
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 9:11 pm     Reply with quote

temtronic wrote:
OK, I took ex_pbutt.c, copied, renamed,edited to move the function 'clear_delta()' AFTER main().

It FAILED to compile.. 'undefined identifier.. ' error message

This, to me, confirms that functions MUST be coded before main() or at least before they are used. A function could be called from another function.

So it's still a mystery to me why the original ex_pbutt failed for you.


In C and C++ you have 2 options:
1. Define the function before you use it (above main example)
2. Forward declare the function before you use it (above main in your example)

But at least one of those is required in C
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 1:08 am     Reply with quote

The behaviour you have is exactly what you get, if the compiler cannot
find the DLL containing the actual processor code.
I can make it behave like this if I remove the compiler directory from the
path statement. The compiler gets called (since you are explicitly giving
it's full path when calling it), but it cannot then find the sub-components
that actually tell it how to code the functions used by the processor.
It'll also do the same if the DLL sub-directory does not exist, or does not
contain the correct DLL's.
Basically CCS has the compiler itself, and then in this DLL directory is all
the library 'code' needed for this to work. That it is failing on a 'core'
function, suggests it is not finding this library correctly.
Other obvious possibility is that your DLL has got corrupted. Try re-installing.
This might well fix this.
The answers being given above would all apply if this was one of 'your'
functions giving the error, but this isn't the case.
The only other possibility is that +FM is not being accepted. This particular
example loads different processor defines based upon which compiler
is being used. If the compiler type was not being passed, then no processor
would be defined, and therefore no definitions would exist for these
internal functions.....

One thing I realise.
You do realise you have to make a copy of the examples before you can
compile them?.
If I open pbutt.c, it says this is an example do you want to open it in
place, or copy it. If I say 'open in place', I cannot then compile it.
Have to copy, and then it can be compiled. The permissions on the
example directory, do not allow writes, and the compiler needs to write.
In Linux this is likely to be even better implemented. If you notice, Jay
above says he copied it, before he compiled.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 9:28 am     Reply with quote

re: One thing I realise.
You do realise you have to make a copy of the examples before you can
compile them?.
If I open pbutt.c

interesting.. i didn't run into that at all....
from MPLAB8v92, created a new project,added ex_pbutt.c, compiled, happy.
I can't be THAT lucky... oh yeah, starter won't spin on forklift, the one with the flat tire ,sitting outside in the snow and ice....

anyone got a trained small octopus ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 10:21 am     Reply with quote

You are creating a new project. Where?.
He is compiling from command line.
The default is for the examples directory to not have write permissions.
In the command line he shows it will try to compile in the examples
directory,
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 10:32 am     Reply with quote

I do it within the MPLAB 8v92 IDE.
same as I've done for 'ever'.....
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 11:23 am     Reply with quote

Creating in MPLAB, 8.92, it will normally create the project inside the
<user name>/projects directory, and compile there. You have write
permissions here.
TTM



Joined: 08 Feb 2022
Posts: 7
Location: France

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 2:34 pm     Reply with quote

Hello everyone,

Thanks for looking into this with so much passion :-)

So again I'M USING A LINUX VERSION, so I do not have a DLL or whatever path to setup. And more than this, running the command from the installation directory doesn't bring any issue for path issue as ... there's only one exec file and one lib file, both at the same location.
So this is NOT an issue with the path

Having said that, the post of jeremiah pointing the "parser" issue made me test some different stuffs.

So, as the issue is with the "set_tris_b()" function call, and since the device file is properly included, I tried to remove the declaration in the device file, and defined it in the same source file, like this:

#include <16F873.h>

#use delay(crystal=20mhz)
#use rs232(icd) //Text through the ICD
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) //Text through the UART

void set_tris_b(int8 value)
{
int x;

}
...

void main() {
char pos1, pos2;

set_tris_b(0);
output_b(0);

pos1='0';
pos2='1';

while(TRUE) {
display(pos1,pos2);
if(kbhit()) {
pos1=pos2;
pos2=getc();
}
}

}



and guess what ? The issue moved to the next function call output_b()

I did the same for this function as below:


void set_tris_b(int8 value)
{
int x;

}

void output_b(int8 value)
{
int x;

}


and obviously, now the stuff compile and link without problem.

Now, if I read back what temtronic was saying with

if you try

main()
function1()
functio2()

you'll get the error

UNLESS you type blank 'prototypes' before main()


I totally agree but it's absolutely NOT the same problem: in your case temtronic, you'll get a "Undefined identifier ... function1()

which is normal, in my case it's a

Function used but not defined set_tris_b()

Which clearly "states" (well, this is how I interpret it, but I let CCS confirming it) that it is a linker issue (the function was NOT FOUND in the standard library).

I will update you as soon as I get some info

And again, I'M UNDER LINUX :-)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group