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.

Extern "C" usage dm6467



Hi,

 

i'm using dvsdk 1.4 with my dm6467 board. Now, i'm trying compile a application qith c and c++ source code. To do this, i read that i have to use " extern "C" " keyword, but i'm getting "sender/sender.hh:48: error: parse error before string constant " error.

I'm wondering if it is happening because TI gcc and g++ cross compiles does not support this keyword. This is true?? 

 

Does anyone knows if there is another way to achieve what i'm trying to do?

 

Regards,

  • Do you use extern "C" only for C++ sources?
    I think that it should not appear in C compiled modules.
    There is the trick for using them only when compilation is done in C++ :

    Some_common_header.h:

    #ifdef __cplusplus
    extern "C" {
    #endif

    // here is the common contents for C and C++

    #ifdef  __cplusplus
    }
    #endif

    Regards
    Piotr Romaniuk, Ph.D.
    ELESOFTROM

  • Thanks Piotr for your fast reply.

    Yes, most generally i will use extern "C" for C++ sources. After implementing your sugestion, i can give a feedback here.

    But, the point is (and now maybe is unsolvable), i have one thread (my sender thread which uses TI and Live555 libraries) writen in C++ source and i need this one be seen by the main function of my application (which is, as all other sources, in C). 

    Does one know if is it possible?

     

    Tanks in advance,

  • There are no hopeless cases :)
    In your program there are two possible cases:

    1) you have common interface to your thread and the interface is compatible with C (only structures and functions are defined in this interface).
    Because you use it in C and C++ you need that extern "C" . Generally it determines how functions are identified by compiler (in C++ function names contain arguments list coded by letters, in C only the original name is used, sometimes with underscore prefix). The solution to this issue I described before.

    2) you have interface to your thread that is object C++, so you cannot link it with regular C. This case is not hopeless, at least you can provide a wrapper for your classes, the wrapper should have C interface and implement functions like: object creation/destroy all methods of the class. Objects are identified by a pointer to a structure that contains all data of the object (but not methods). When you need to call class method you will call wrapper function and use as first argument object pointer.
    This is what is behind classes and is done by C++ compiler

    As long as you don't need inheritance and protection of class fields you can handle objects in C.

    for example:

    _______________________ C++ class definition  __________________________
    class MyClass{
         int field1;
         char field2;
         MyClass( int field1_init );
         void MethodExample( int arg);
         ~MyClass();
    };

    ______ C header (interface) - include it in your C module_________
    struct MyClass_s{
         int field1;
        char field2;
    };

    MyClass_s * MyClass_Create( );
    void MyClass_Method( MyClass_s * Object, int field1_init );
    void MyClass_Destroy( MyClass_s * Object);

    ________ C++ module (wrapper) - here you can use C++ syntax ______
    MyClass_s * MyClass_Create( )
    {
         //somehow allocate memory for object, e.g.
         MyClass * new_object = new MyClass;
         return (MyClass_s *)new_object;
    }

    void MyClass_Method( MyClass_s * Object, int field1_init )
    {
         MyClass * object = (MyClass*) Object;
         object->MethodExample( field1_init );
    }

    void MyClass_Destroy( MyClass_s * Object)
    {
         //free object memory
         MyClass * object = (MyClass *) Object;
         delete object;
    }

    _______________ your module in C, where you use objects from C++ _____________

    MyObject_s * myObj1; //store here your object identification
    myObj1 = MyClass_Create();//create you object via the wrapper

    MyClass_Method( myObj1, 12 );//example of object method call in C

    MyClass_Destroy( myObj1 );//destroy your object

    Regards
    Piotr Romaniuk, Ph.D.
    ELESOFTROM