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 support@ccsinfo.com

Error 112 Function used but not defined

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 26

View user's profile Send private message

Error 112 Function used but not defined
PostPosted: Thu Jul 07, 2022 1:56 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Thu Jul 07, 2022 3:03 am     Reply with quote

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: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Thu Jul 07, 2022 3:04 am     Reply with quote

You should include peripherals.c after peripherals.h
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 07, 2022 3:39 am     Reply with quote

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: 26

View user's profile Send private message

Error 112 Function used but not defined
PostPosted: Thu Jul 07, 2022 4:15 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Thu Jul 07, 2022 4:36 am     Reply with quote

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: 26

View user's profile Send private message

Error 112 Function used but not defined
PostPosted: Fri Jul 08, 2022 4:27 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Fri Jul 08, 2022 6:23 am     Reply with quote

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: 26

View user's profile Send private message

Error 112 Function used but not defined
PostPosted: Fri Jul 08, 2022 6:28 am     Reply with quote

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: 1910
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Jul 08, 2022 7:14 am     Reply with quote

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!!!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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