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

Compilation error "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
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

Compilation error "Function used but not defined"
PostPosted: Wed Mar 13, 2019 4:02 am     Reply with quote

Dear Sirs and Madams!

I've inherited a project from my ex coworker, working now in MPLAB X IDE ver. 5.1.0 for Windows. It compiled ok because it had only one header and implementation (RFECB_XPAND_VDC_v102.h/RFECB_XPAND_VDC_v102.c, which are basicly main.h/main.c) file. Now, to keep the code organized, I've added another header file:
Code:

/*
 * File:   XvEmiterModes.h
 * Author: user
 *
 * Created on March 12, 2019, 12:04 PM
 */

#ifndef XVEMITERMODES_H
#define   XVEMITERMODES_H

#ifdef   __cplusplus
extern "C" {
#endif

/*
 * @author user
 * @brief This enum describes current emmiter working mode
 * @enum xvTEmitterMode
 */
typedef enum
{
    XV_3D_X1=0,             ///< Classic 3D mode
    XV_2D_X2,               ///< so called Dual View
    XV_2D_X4,               ///< so called Quadruple View
    XV_3D_X2,               ///< 3D x2
    XV_3D_X3                ///< 3D x3
} xvTEmitterMode;

/*
 * @author user
 * @brief This constant defines number of emiter modes (size of upper struct)
 */
const uint8_t XV_NUMBER_OF_EMITTER_MODES=5;

/*
 * @author user
 * @brief returns first emitter mode in list (its default mode - single 3D)
 */
extern xvTEmitterMode xvGetFirstMode(void);

/*
 * @author user
 * @brief returns last emitter mode in list (triple 3D)
 */
extern xvTEmitterMode xvGetLastMode(void);

/*
 * @author user
 * @brief returns next mode regarding current mode
 */
extern xvTEmitterMode xvGetNextEmitterMode(xvTEmitterMode xvCurrentEmitterMode);

/*
 * @author user
 * @brief returns previous mode regarding current mode
 */
extern xvTEmitterMode xvGetPreviousEmitterMode(xvTEmitterMode xvCurrentEmitterMode);

#ifdef   __cplusplus
}
#endif

#endif   /* XVEMITERMODES_H */

and its implemetation file:
Code:

#include "XvEmiterModes.h"

xvTEmitterMode xvGetFirstMode(void)
{
    return XV_3D_X1;
}   // xvGetFirstMode

xvTEmitterMode xvGetLastMode(void)
{
    return XV_3D_X3;
}   // xvGetLastMode

xvTEmitterMode xvGetNextEmitterMode(xvTEmitterMode xvCurrentEmitterMode)
{
    switch(xvCurrentEmitterMode)
    {
        case xvTEmitterMode.XV_3D_X1:
        {
            return xvTEmitterMode.XV_2D_X2;
        }   // case
       
        case xvTEmitterMode.XV_2D_X2:
        {
            return xvTEmitterMode.XV_2D_X4;
        }   // case
       
        case xvTEmitterMode.XV_2D_X4:
        {
            return xvTEmitterMode.XV_3D_X2;
        }   // case
       
        case xvTEmitterMode.XV_3D_X2:
        {
            return xvTEmitterMode.XV_3D_X3;
        }   // case
       
        case xvTEmitterMode.XV_3D_X3:
        {
            return xvTEmitterMode.XV_3D_X1;
        }   // case
       
        default:
        {
            break;
        }   // default
    }   // switch
}   // xvGetNextEmiterMode

xvTEmitterMode xvGetPreviousEmitterMode(xvTEmitterMode xvCurrentEmitterMode)
{
    case xvTEmitterMode.XV_3D_X1:
    {
        return xvTEmitterMode.XV_3D_X3;
    }   // case

    case xvTEmitterMode.XV_2D_X2:
    {
        return xvTEmitterMode.XV_3D_X1;
    }   // case

    case xvTEmitterMode.XV_2D_X4:
    {
        return xvTEmitterMode.XV_2D_X2;
    }   // case

    case xvTEmitterMode.XV_3D_X2:
    {
        return xvTEmitterMode.XV_2D_X4;
    }   // case

    case xvTEmitterMode.XV_3D_X3:
    {
        return xvTEmitterMode.XV_3D_X2;
    }   // case

    default:
    {
        break;
    }   // default
}   // xvGetPreviousEmiterMode

Now, in main file I include this header file with:
Code:

#include "XvEmiterModes.h"

and when I try to use function from XvEmiterModes.h:
Code:

xvTEmitterMode xvCurrentEmitterMode=xvGetFirstMode();

I get following error:
Quote:

E:\Projects\RFECB_XPAND_VDC_v102\RFECB_XPAND_VDC_v102.c:249:1: Error#112 Function used but not defined: ... xvGetFirstMode SCR=3264

The new file ARE NOT ADDED to project (not visible in Project tree):
[img]https://ibb.co/vqfCMJx[/img]
, however, if I add them:
[img]https://ibb.co/Pzthykq[/img]
, I get following error:
Quote:

E:\Projects\RFECB_XPAND_VDC_v102\XvEmiterModes.h:11:2: Error#128 A #DEVICE required before this line

Why and how do I fix this? Eliminating files and putting everything into main file is not an option, becuase I want the code to be structured and well handled.[/img]
temtronic



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

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 5:19 am     Reply with quote

We'd have to see the first 10-15 lines of code but the
'device' error points to NOT having the picprocessor.h file as the first line of code.

The 'function used but not defined' means the program is trying to use a function that hasn't yet been loaded in. Again, this is a 'sequence' issue.
You have used 'extern' which may be a problem.

seasoned CCS C programmers will know for sure....
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 5:45 am     Reply with quote

temtronic wrote:
We'd have to see the first 10-15 lines of code but the
'device' error points to NOT having the picprocessor.h file as the first line of code.

The 'function used but not defined' means the program is trying to use a function that hasn't yet been loaded in. Again, this is a 'sequence' issue.
You have used 'extern' which may be a problem.

seasoned CCS C programmers will know for sure....

Hmm, if I remove all references in the code and in the project to function in those two files, the compile process is success without any warning, so pic processor is included in the first line in RFECB_XPAND_VDC_v102.h:
Code:

//RFECB_XPAND_VDC_vxxx  header file 
#include "16F636.h"
#device CONST=READ_ONLY
#include <stdint.h>
#include <stdlib.h>

If I add #include directive after stdlib.h, I get first lineerror. Why is that?
temtronic



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

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 6:13 am     Reply with quote

I'd have to see the complete error message but it may be that you have the same named function in 2 different places.
I've seen this before when two programmers create their own functions and their code is 'merged' into one program.
Say 'A' made 'myfunction()'
AND 'B' made 'myfunction()'
then in the program

...
myfunction();
myfunction();
...

error as the compiler sees TWO different myfunction();

it should be myfunctonA(); and myfunctionB();
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 6:25 am     Reply with quote

temtronic wrote:
I'd have to see the complete error message but it may be that you have the same named function in 2 different places.
I've seen this before when two programmers create their own functions and their code is 'merged' into one program.
Say 'A' made 'myfunction()'
AND 'B' made 'myfunction()'
then in the program

...
myfunction();
myfunction();
...

error as the compiler sees TWO different myfunction();

it should be myfunctonA(); and myfunctionB();


Hmm, where, I cannot find it? Which file/line?
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 13, 2019 6:38 am     Reply with quote

I think there's something with CCS where if you haven't included the .c file, then it just never sees the definition.

Check out the included driver files. For example to use the modbus driver, you #include <modbus.c> in your own program. modbus.c in turn will #include <modbus.h>

In all of my own header files, I combine the declarations and definitions. Essentially, if I were to do it, I would have put the contents of XvEmiterModes.c under all of the declarations in XvEmiterModes.h
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 7:05 am     Reply with quote

dluu13 wrote:
I think there's something with CCS where if you haven't included the .c file, then it just never sees the definition.

Check out the included driver files. For example to use the modbus driver, you #include <modbus.c> in your own program. modbus.c in turn will #include <modbus.h>

In all of my own header files, I combine the declarations and definitions. Essentially, if I were to do it, I would have put the contents of XvEmiterModes.c under all of the declarations in XvEmiterModes.h

Hmm, it works now! I've moved all implementations to .h file and it compiles without error! Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 7:10 am     Reply with quote

This sound like the old compilation order thing with MPLAB

To use MPLAB, _only_ put your 'main' C file in the 'source code' section.
Put your other files in the 'header' section.
Ensure your main file is setup to include everything it needs.

Your 'extern' setups, suggest you are trying to use multiple compilation
units. Honestly don't. CCS is at heart a single pass compiler.
It has been modified in recent years to support MCU's, but it still
generates more efficient code if it is allowed to do a single pass compilation.
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 6:47 pm     Reply with quote

In MPLABX, if you right click on the Source Files folder in the project view and go to Properties, then on the far right should be some checkboxes for what to exclude. Exclude all .c files but your main.
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