Call function outside of current namespace in C++

span

I'm trying to call a function defined in a C file from my CPP code and I think I am having issues getting the correct namespace. When compiling I get the error: "Undefined reference to 'Get'".

My C header:

// c.h
#ifndef C_H
#define C_H

#ifdef __cplusplus
    extern "C" {
#endif

typedef enum
{
    VAL_A1,
    VAL_A2
} TYPE_A;

typedef enum
{
    VAL_B1,
    VAL_B2
} TYPE_B;

typedef enum
{
    VAL_C1,
    VAL_C2
} TYPE_C;

typedef struct
{
    TYPE_B b;
    TYPE_C c;
} TYPE_D;

TYPE_A Get(TYPE_B b, TYPE_D *d);

#ifdef __cplusplus
    }
#endif

#endif

And my CPP file:

// main.cpp
...

extern "C" {
    #include "c.h"
}

...

namespace MyNamespace
{
    ...

    MyClass::MyFunc()
    {
        TYPE_D d;
        // None of these calls will compile
        // Get(VAL_B1, &d);
        // ::Get(VAL_B1, &d);
    }

    ...
}

I have tried calling without namespace reference and also with the "root" namespace using "::" with no luck. Any help is appreciated. I've read through this which seems to clarify it but I don't really understand it:

using C++ with namespace in C

Mike Seymour

"Undefined reference" means that the function has been declared (in the header), but not defined. You'll need to define the function in a source file somewhere (presumably the C file you refer to), and make sure that is linked when you build the program.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++ error to call void function in namespace

From Dev

Angular 2 - Call a function that exists outside of the current class

From Dev

Call a function outside main ()

From Dev

Call a function outside main ()

From Dev

popup outside of a function call

From Dev

How to call specific namespace's function in C#

From Dev

call var in function to outside the function

From Dev

Does c++ allow function call outside any funtion?

From Dev

Nashorn: Call function inside of a namespace

From Dev

Call a function of a library, outside the library

From Dev

Call This Function Outside of Form Submit

From Dev

Call controller function from outside

From Dev

How to Call PHP function outside

From Dev

Call MainActivity function outside the class

From Dev

Define C# class outside of any namespace

From Dev

Why the defines inside a c++ namespace works outside the namespace?

From Dev

Should I put the "using namespace" inside or outside of a namespace in C++

From Dev

Why the defines inside a c++ namespace works outside the namespace?

From Dev

Bind scope to function outside of function call

From Dev

Call javascript function result outside function

From Dev

Using a defined variable from outside the current function

From Dev

call vim function with current word

From Dev

UndefinedFunctionException: Attempted to call function from namespace Controller

From Dev

Call function from different class and namespace

From Dev

Attempted to call function "split" from namespace "Controller"

From Dev

Attempted to call function from namespace - Silex PHP

From Dev

C++ ADL: Call a function from the namespace which a particular type belongs to

From Dev

How can I call clearInterval outside of a function in jQuery? Outside the setInterval

From Dev

How can I call clearInterval outside of a function in jQuery? Outside the setInterval

Related Related

  1. 1

    C++ error to call void function in namespace

  2. 2

    Angular 2 - Call a function that exists outside of the current class

  3. 3

    Call a function outside main ()

  4. 4

    Call a function outside main ()

  5. 5

    popup outside of a function call

  6. 6

    How to call specific namespace's function in C#

  7. 7

    call var in function to outside the function

  8. 8

    Does c++ allow function call outside any funtion?

  9. 9

    Nashorn: Call function inside of a namespace

  10. 10

    Call a function of a library, outside the library

  11. 11

    Call This Function Outside of Form Submit

  12. 12

    Call controller function from outside

  13. 13

    How to Call PHP function outside

  14. 14

    Call MainActivity function outside the class

  15. 15

    Define C# class outside of any namespace

  16. 16

    Why the defines inside a c++ namespace works outside the namespace?

  17. 17

    Should I put the "using namespace" inside or outside of a namespace in C++

  18. 18

    Why the defines inside a c++ namespace works outside the namespace?

  19. 19

    Bind scope to function outside of function call

  20. 20

    Call javascript function result outside function

  21. 21

    Using a defined variable from outside the current function

  22. 22

    call vim function with current word

  23. 23

    UndefinedFunctionException: Attempted to call function from namespace Controller

  24. 24

    Call function from different class and namespace

  25. 25

    Attempted to call function "split" from namespace "Controller"

  26. 26

    Attempted to call function from namespace - Silex PHP

  27. 27

    C++ ADL: Call a function from the namespace which a particular type belongs to

  28. 28

    How can I call clearInterval outside of a function in jQuery? Outside the setInterval

  29. 29

    How can I call clearInterval outside of a function in jQuery? Outside the setInterval

HotTag

Archive