This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280040-Q1: Driverlib compilation error into a C++ project

Part Number: TMS320F280040-Q1
Other Parts Discussed in Thread: C2000WARE

Hello folks, 

I'm facing a similar problem. I'm starting a new project and I'd like to use the driverlib with my previous C++ code. I started importing the driverlib empty_project and when I rename the main.c to main.cpp, I'm getting this compilation errors:

>> Compilation failure
subdir_rules.mk:9: recipe for target 'driverlib_main.obj' failed
"C:/ti/c2000/C2000Ware_4_00_00_00/driverlib/f28004x/driverlib/erad.h", line 380: error #121: return value type does not match the function type
"../driverlib_main.cpp", line 58: warning #337-D: linkage specification is not allowed
At end of source: error #68: expected a "}"
2 errors detected in the compilation of "../driverlib_main.cpp".
gmake: *** [driverlib_main.obj] Error 1
gmake: Target 'all' not remade because of errors.

The compiler points to an error at this function:

static inline ERAD_Owner
ERAD_getOwnership()
{
//
// Read Global Owner register and return value
//
return((ERAD_Owner)(HWREGH(ERAD_GLOBAL_BASE + ERAD_O_GLBL_OWNER) &
ERAD_GLBL_OWNER_OWNER_M) >> ERAD_GLBL_OWNER_OWNER_S);
}

However, I have no idea how to solve it.

I've tried to use the extern "C" directive, but there was no difference, I'm still getting the same error.

extern "C"
{
#include "driverlib.h"
#include "device.h"
}

The project with the main.c compiles with no error neither warnings. 

Do you guys have experience using driverlib in C++ projects? Is this a good idea?

Cheers,

Luciano

  • I started importing the driverlib empty_project and when I rename the main.c to main.cpp, I'm getting this compilation errors

    I can repeat this. Looks to be two problems:

    1) The static inline ERAD_getOwnership() function in C2000Ware_4_00_00_00\driverlib\f28004x\driverlib\erad.h contains an implicit cast from an integer expression to an enumeration. This is legal in C, but not in C++. Constructs valid in C but not in C++ contains:

    C++ is also more strict in conversions to enums: ints cannot be implicitly converted to enums as in C.

    To avoid the error think the ERAD_getOwnership() function in erad.h should be changed from:

    static inline ERAD_Owner
    ERAD_getOwnership()
    {
        //
        // Read Global Owner register and return value
        //
        return((ERAD_Owner)(HWREGH(ERAD_GLOBAL_BASE + ERAD_O_GLBL_OWNER) &
                            ERAD_GLBL_OWNER_OWNER_M) >> ERAD_GLBL_OWNER_OWNER_S);
    }

    To:

    static inline ERAD_Owner
    ERAD_getOwnership()
    {
        //
        // Read Global Owner register and return value
        //
        return(ERAD_Owner)((HWREGH(ERAD_GLOBAL_BASE + ERAD_O_GLBL_OWNER) &
                            ERAD_GLBL_OWNER_OWNER_M) >> ERAD_GLBL_OWNER_OWNER_S);
    }

    2) For At end of source: error #68: expected a "}" guessed the issue was one C2000Ware include file which didn't have a matching closing } for an extern "C" block.

    Searching all C2000Ware f280004x/driverlib include files for #ifdef __cplusplus found C2000Ware_4_00_00_00\driverlib\f28004x\driverlib\pmbus_common.h which has an opening block:

    //*****************************************************************************
    //
    // If building with a C++ compiler, make all of the definitions in this header
    // have a C binding.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    extern "C"
    {
    #endif

    But is missing the closing block:

    //*****************************************************************************
    //
    // Mark the end of the C bindings section for C++ compilers.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    }
    #endif

    The missing closing block explains why the include file can be included when included from a C program, but generates an error when included from a C++ program.

    Do you guys have experience using driverlib in C++ projects? Is this a good idea?

    Not sure if TI officially support, and test, using driverlib from C++ projects.

  • Thank you so much, Chester. You were precise! I did the changes as you said and the errors vanished.

    Thanks for answering so fast.

    Cheers,

    Luciano