View previous topic :: View next topic |
Author |
Message |
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Error 112 Function used but not defined |
Posted: Thu Jul 07, 2022 1:56 am |
|
|
I am new to CCS IDE. I am moving away from old Hi-Tech compiler to CCS.
I have so many codes written in Hi-Tech and trying to import into CCS.
As for Hi-Tech, I used to have multiple files in the project. Functions and Variables to be used across the project are defined in the respective header file. That header file is included in the file which needs to call and use the functions/variables.
However, doing same does not work in CCS IDE.
For Example:-
peripherals.c
Code: | void setup_peripherals (void)
{
code
}
|
peripherals.h
Code: | void setup_peripherals (void); |
another file
main.c
Code: |
#include peripherals.h
while (1)
{
setup_peripherals (); // I am getting Error 112 on this line.
} |
_________________ MVadukul |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jul 07, 2022 3:03 am |
|
|
You need to include peripherals.c.
You don't actually need peripherals.h.
You would have been separately compiling peripherals.c, and then telling
the Hitech compiler to link the result of this compilation. By default, the
best way to work with CCS, is to simply compile everything at once.
You can do multiple compilation units (but you would have to add definitions
of what the files contain and import these), but the compiler works most
efficiently (in it's optimisations), by just compiling everything at once. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 479 Location: Montenegro
|
|
Posted: Thu Jul 07, 2022 3:04 am |
|
|
You should include peripherals.c after peripherals.h |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 07, 2022 3:39 am |
|
|
The CCS compiler manual used to have compiler error messages listed
at the end. I found an old pdf of the manual on my PC. It says:
Quote: |
Function used but not defined -
The indicated function had a prototype but was never defined in the program. |
|
|
|
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Error 112 Function used but not defined |
Posted: Thu Jul 07, 2022 4:15 am |
|
|
Thank you.
I am trying few things and it is quite different to MPLAB Hi-Tech, in terms of how it compiles various files.
I think this is going to be a learning curve but hoping to get going.
The issue is the structure of the existing projects which do not marry up with CCS IDE and general setup. _________________ MVadukul |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jul 07, 2022 4:36 am |
|
|
Yes, it is a fundamental difference.
CCS by default, and originally, was always a single unit compiler. No linking.
HiTech, was always a linking compiler. So you compile your functions as
libraries, and in the main code only include the prototypes for these, then
link the libraries in at the final stage of the build.
He is including the prototypes, but not the actual code, which is what the
error says.
Now CCS can be used like this, but he would have to make a build file
for this, and specify #import directives etc..
Look at 'Linker' in the manual for a description of how to do this (and an
example).
Much easier though to just get rid if the #include "peripherals.h" line, and
replace this with #include "peripherals.c"
This way the code for the functions is included (no need for separate
prototypes), and the code will compile. |
|
|
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Error 112 Function used but not defined |
Posted: Fri Jul 08, 2022 4:27 am |
|
|
Thank you for your comments. As I said, I am going through the pain of making the code compatible with CCS. I guess its the hurdle.
As most of my functions are in different files and the functions are defined in header files. If I include header and c both in my main file, that should clear the issue.
However, I am still getting this annoying Error 112: function used but not defined! If i delete the definition from header file, it says the function is not declared. Basically, it sees the definition and yet gives me the error function not defined! its baffling. _________________ MVadukul |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri Jul 08, 2022 6:23 am |
|
|
You were showing the header file include not having inverted commas or
brackets. These should be used.
"" says search in the main directory, then the path
<> says search in the path then the main directory.
Other thing is 'order' #include the header files first, then the code files.
Otherwise is a function uses something else from another include it
will complain since it has not been defined before use. So:
Code: |
#include processor file
FUSES
CLOCK setup
peripheral setups (RS232 I2 etc.)
#include "header1.h"
#include "header2.h" //for all the headers
//Only now #include the code files
//main code
|
|
|
|
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Error 112 Function used but not defined |
Posted: Fri Jul 08, 2022 6:28 am |
|
|
Thanks.
It is all sorted now. I learnt few things.
1) In main file, need to include all of the headers and all of the source c files.
2) All the source c files and c headers to have #ifndef to avoid duplication.
3) All other source files should not have included any .c files as they are already added to main file.
Once I do above changes, the code compiles and now need to make changes to suit CCS but basic configuration and structure is done. _________________ MVadukul |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Jul 08, 2022 7:14 am |
|
|
To keep things cleaner I declare the .h files in the related .c files where
possible which cuts down in the "includes" in the main program especially
in larger programs. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
|