How to use internal c++ class types from C? [duplicate]How to call C++ function from C?Why can't templates be within extern “C” blocks?Using “extern C” on non function call related declarationsHow do you set, clear, and toggle a single bit?What are the differences between a pointer variable and a reference variable in C++?Storing C++ template function definitions in a .CPP fileWhat are POD types in C++?The Definitive C++ Book Guide and ListHow to determine a Python variable's type?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Combining C++ and C - how does #ifdef __cplusplus work?Why is reading lines from stdin much slower in C++ than Python?

Why should we care about syntactic proofs if we can show semantically that statements are true?

In Pokémon Go, why does one of my Pikachu have an option to evolve, but another one doesn't?

Can I legally make a real mobile app based on a fictional app from a TV show?

Why aren’t emergency services using callsigns?

Why did Gandalf use a sword against the Balrog?

Team goes to lunch frequently, I do intermittent fasting but still want to socialize

Accidentals - some in brackets, some not

How to use grep to search through the --help output?

Was this a rapid SCHEDULED disassembly? How was it done?

During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?

Is it okay for a ticket seller to grab a tip in the USA?

How can I iterate this process?

How can you evade tax by getting employment income just in equity, then using this equity as collateral to take out loan?

Could one become a successful researcher by writing some really good papers while being outside academia?

Three legged NOT gate? What is this symbol?

Why do oscilloscopes use SMPS instead of linear power supply?

First amendment and employment: Can an police department terminate an officer for speech?

Optimal way to extract "positive part" of a multivariate polynomial

Generator for parity?

Acceptable to cut steak before searing?

Author changing name

Table content alignment to centre using tabular

Y2K... in 2019?

Are there any differences in causality between linear and logistic regression?



How to use internal c++ class types from C? [duplicate]


How to call C++ function from C?Why can't templates be within extern “C” blocks?Using “extern C” on non function call related declarationsHow do you set, clear, and toggle a single bit?What are the differences between a pointer variable and a reference variable in C++?Storing C++ template function definitions in a .CPP fileWhat are POD types in C++?The Definitive C++ Book Guide and ListHow to determine a Python variable's type?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Combining C++ and C - how does #ifdef __cplusplus work?Why is reading lines from stdin much slower in C++ than Python?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3
















This question already has an answer here:



  • How to call C++ function from C?

    6 answers



  • Why can't templates be within extern “C” blocks?

    5 answers



  • Using “extern C” on non function call related declarations

    3 answers



I have a C++ class MyClass that declare a public enum type MyEnum, and I want to use that enum in a C file. How can I do that ?



I tried to declare my functions in a C++ file and then put everything as extern "C", but sadly I am using some functions defined in big_hugly_include.h and this header does not like being included as external "C" (it gives me a template with C linkage error).



I cannot (don't want to) change this include, and I need it because it defines my_function_from_big_include. Am I stuck ?




my_class_definition.h :



class MyClass

public:
// I would like to keep it that way as it is mainly used in C++ files
typedef enum

MY_ENUM_0,
MY_ENUM_1,
MY_ENUM_2
MyEnum;
;



Try 1 : my_c_function_definition.c :



#include "my_class_definition.h"

// I cannot remove this header
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// I need to call this function with the enum from the C++ class
// This doesn't work (class name scope does not exist in C)
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);




Try 2 : my_c_function_definition.cpp :



#include "my_class_definition.h"

extern "C"


// Error template with C linkage
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"




Edited in response to @artcorpse



Try 3 : my_c_function_definition.cpp :



#include "my_class_definition.h"

// Error multiple definition of [...]
// Error undefined reference to [...]
#include "big_hugly_include.h"

extern "C"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"










share|improve this question
















marked as duplicate by Kamil Cuk, Kamiccolo, Umair, Rekshino, cegfault Mar 27 at 15:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 9





    If your enum is in a class, you can't access it from C.

    – Matthieu Brucher
    Mar 27 at 8:02






  • 1





    don't think there is much you can do other than move/copy your enum into the global namespace

    – Alan Birtles
    Mar 27 at 8:02






  • 1





    Why that typedef enum ... in C++ ?

    – bruno
    Mar 27 at 8:07












  • your .h is not your real .h, since at least class or struct and ; are missing. Are there other things that you've left out ?

    – Christophe
    Mar 27 at 8:17






  • 1





    The duplicate provided to close this answer is IMHO not an appropriate one, since it doesn’t address the issue with types.

    – Christophe
    Mar 27 at 16:44

















3
















This question already has an answer here:



  • How to call C++ function from C?

    6 answers



  • Why can't templates be within extern “C” blocks?

    5 answers



  • Using “extern C” on non function call related declarations

    3 answers



I have a C++ class MyClass that declare a public enum type MyEnum, and I want to use that enum in a C file. How can I do that ?



I tried to declare my functions in a C++ file and then put everything as extern "C", but sadly I am using some functions defined in big_hugly_include.h and this header does not like being included as external "C" (it gives me a template with C linkage error).



I cannot (don't want to) change this include, and I need it because it defines my_function_from_big_include. Am I stuck ?




my_class_definition.h :



class MyClass

public:
// I would like to keep it that way as it is mainly used in C++ files
typedef enum

MY_ENUM_0,
MY_ENUM_1,
MY_ENUM_2
MyEnum;
;



Try 1 : my_c_function_definition.c :



#include "my_class_definition.h"

// I cannot remove this header
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// I need to call this function with the enum from the C++ class
// This doesn't work (class name scope does not exist in C)
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);




Try 2 : my_c_function_definition.cpp :



#include "my_class_definition.h"

extern "C"


// Error template with C linkage
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"




Edited in response to @artcorpse



Try 3 : my_c_function_definition.cpp :



#include "my_class_definition.h"

// Error multiple definition of [...]
// Error undefined reference to [...]
#include "big_hugly_include.h"

extern "C"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"










share|improve this question
















marked as duplicate by Kamil Cuk, Kamiccolo, Umair, Rekshino, cegfault Mar 27 at 15:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 9





    If your enum is in a class, you can't access it from C.

    – Matthieu Brucher
    Mar 27 at 8:02






  • 1





    don't think there is much you can do other than move/copy your enum into the global namespace

    – Alan Birtles
    Mar 27 at 8:02






  • 1





    Why that typedef enum ... in C++ ?

    – bruno
    Mar 27 at 8:07












  • your .h is not your real .h, since at least class or struct and ; are missing. Are there other things that you've left out ?

    – Christophe
    Mar 27 at 8:17






  • 1





    The duplicate provided to close this answer is IMHO not an appropriate one, since it doesn’t address the issue with types.

    – Christophe
    Mar 27 at 16:44













3












3








3









This question already has an answer here:



  • How to call C++ function from C?

    6 answers



  • Why can't templates be within extern “C” blocks?

    5 answers



  • Using “extern C” on non function call related declarations

    3 answers



I have a C++ class MyClass that declare a public enum type MyEnum, and I want to use that enum in a C file. How can I do that ?



I tried to declare my functions in a C++ file and then put everything as extern "C", but sadly I am using some functions defined in big_hugly_include.h and this header does not like being included as external "C" (it gives me a template with C linkage error).



I cannot (don't want to) change this include, and I need it because it defines my_function_from_big_include. Am I stuck ?




my_class_definition.h :



class MyClass

public:
// I would like to keep it that way as it is mainly used in C++ files
typedef enum

MY_ENUM_0,
MY_ENUM_1,
MY_ENUM_2
MyEnum;
;



Try 1 : my_c_function_definition.c :



#include "my_class_definition.h"

// I cannot remove this header
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// I need to call this function with the enum from the C++ class
// This doesn't work (class name scope does not exist in C)
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);




Try 2 : my_c_function_definition.cpp :



#include "my_class_definition.h"

extern "C"


// Error template with C linkage
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"




Edited in response to @artcorpse



Try 3 : my_c_function_definition.cpp :



#include "my_class_definition.h"

// Error multiple definition of [...]
// Error undefined reference to [...]
#include "big_hugly_include.h"

extern "C"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"










share|improve this question

















This question already has an answer here:



  • How to call C++ function from C?

    6 answers



  • Why can't templates be within extern “C” blocks?

    5 answers



  • Using “extern C” on non function call related declarations

    3 answers



I have a C++ class MyClass that declare a public enum type MyEnum, and I want to use that enum in a C file. How can I do that ?



I tried to declare my functions in a C++ file and then put everything as extern "C", but sadly I am using some functions defined in big_hugly_include.h and this header does not like being included as external "C" (it gives me a template with C linkage error).



I cannot (don't want to) change this include, and I need it because it defines my_function_from_big_include. Am I stuck ?




my_class_definition.h :



class MyClass

public:
// I would like to keep it that way as it is mainly used in C++ files
typedef enum

MY_ENUM_0,
MY_ENUM_1,
MY_ENUM_2
MyEnum;
;



Try 1 : my_c_function_definition.c :



#include "my_class_definition.h"

// I cannot remove this header
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// I need to call this function with the enum from the C++ class
// This doesn't work (class name scope does not exist in C)
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);




Try 2 : my_c_function_definition.cpp :



#include "my_class_definition.h"

extern "C"


// Error template with C linkage
#include "big_hugly_include.h"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"




Edited in response to @artcorpse



Try 3 : my_c_function_definition.cpp :



#include "my_class_definition.h"

// Error multiple definition of [...]
// Error undefined reference to [...]
#include "big_hugly_include.h"

extern "C"

// foo is called in other C files
void foo()

// That would be ideal
my_function_from_big_include(MyClass::MyEnum::MY_ENUM_0);


// end of extern "C"





This question already has an answer here:



  • How to call C++ function from C?

    6 answers



  • Why can't templates be within extern “C” blocks?

    5 answers



  • Using “extern C” on non function call related declarations

    3 answers







c++ c types calling-convention cross-language






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 18:59









Christophe

43.6k4 gold badges41 silver badges87 bronze badges




43.6k4 gold badges41 silver badges87 bronze badges










asked Mar 27 at 7:53









4nti7rust4nti7rust

568 bronze badges




568 bronze badges





marked as duplicate by Kamil Cuk, Kamiccolo, Umair, Rekshino, cegfault Mar 27 at 15:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Kamil Cuk, Kamiccolo, Umair, Rekshino, cegfault Mar 27 at 15:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Kamil Cuk, Kamiccolo, Umair, Rekshino, cegfault Mar 27 at 15:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 9





    If your enum is in a class, you can't access it from C.

    – Matthieu Brucher
    Mar 27 at 8:02






  • 1





    don't think there is much you can do other than move/copy your enum into the global namespace

    – Alan Birtles
    Mar 27 at 8:02






  • 1





    Why that typedef enum ... in C++ ?

    – bruno
    Mar 27 at 8:07












  • your .h is not your real .h, since at least class or struct and ; are missing. Are there other things that you've left out ?

    – Christophe
    Mar 27 at 8:17






  • 1





    The duplicate provided to close this answer is IMHO not an appropriate one, since it doesn’t address the issue with types.

    – Christophe
    Mar 27 at 16:44












  • 9





    If your enum is in a class, you can't access it from C.

    – Matthieu Brucher
    Mar 27 at 8:02






  • 1





    don't think there is much you can do other than move/copy your enum into the global namespace

    – Alan Birtles
    Mar 27 at 8:02






  • 1





    Why that typedef enum ... in C++ ?

    – bruno
    Mar 27 at 8:07












  • your .h is not your real .h, since at least class or struct and ; are missing. Are there other things that you've left out ?

    – Christophe
    Mar 27 at 8:17






  • 1





    The duplicate provided to close this answer is IMHO not an appropriate one, since it doesn’t address the issue with types.

    – Christophe
    Mar 27 at 16:44







9




9





If your enum is in a class, you can't access it from C.

– Matthieu Brucher
Mar 27 at 8:02





If your enum is in a class, you can't access it from C.

– Matthieu Brucher
Mar 27 at 8:02




1




1





don't think there is much you can do other than move/copy your enum into the global namespace

– Alan Birtles
Mar 27 at 8:02





don't think there is much you can do other than move/copy your enum into the global namespace

– Alan Birtles
Mar 27 at 8:02




1




1





Why that typedef enum ... in C++ ?

– bruno
Mar 27 at 8:07






Why that typedef enum ... in C++ ?

– bruno
Mar 27 at 8:07














your .h is not your real .h, since at least class or struct and ; are missing. Are there other things that you've left out ?

– Christophe
Mar 27 at 8:17





your .h is not your real .h, since at least class or struct and ; are missing. Are there other things that you've left out ?

– Christophe
Mar 27 at 8:17




1




1





The duplicate provided to close this answer is IMHO not an appropriate one, since it doesn’t address the issue with types.

– Christophe
Mar 27 at 16:44





The duplicate provided to close this answer is IMHO not an appropriate one, since it doesn’t address the issue with types.

– Christophe
Mar 27 at 16:44












2 Answers
2






active

oldest

votes


















3















I want to use that enum in a C file. How can I do that?




Enum concept in C++ originates from C, so only thing you have to do is to isolate definition this enum from pure cpp API which is not known to C (remember about name mangling, see below).



Since C do not know in class/struct enums you can't use them. You have to define global scope enumeration or create such enumeration which will map C++ specific enumeration.



So create separate header file where shared API should be located. Do something like this:



// shared C, C++ header
#ifdef __cplusplus
extern "C"

#endif

enum YourMagicEnum
YourMagicEnumAValue,
YourMagicEnumBValue,
YourMagicEnumCValue,
;

void someFunction(YourMagicEnum x);

#ifdef __cplusplus
// extern "C"
#endif


Now this extern "C" is needed only for functions to disable name mangling (in C++ you can do function overloads, so compiler generates names which contain arguments type information).



When defining such function it should also have the extern "C" in front of that definition.



And remember in that header only C specific features and functions can be placed.



Also remember that VLA (Variable-length array) is in C standard, but not in C++ standard (most compiler support VLA for C++).



For more information see this page.






share|improve this answer



























  • I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

    – 4nti7rust
    Mar 27 at 13:37











  • There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

    – Marek R
    Mar 27 at 13:40











  • I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

    – 4nti7rust
    Mar 27 at 13:44











  • only some script which will parse original file and generate respective C header.

    – Marek R
    Mar 27 at 13:54











  • Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

    – 4nti7rust
    Mar 27 at 14:02


















1














Your Try2 is pretty close to a solution. Try to move the include outside extern "C".
I usually just mark each function individually:



extern "C" void foo() 

...



This has the benefit of just exporting the one symbol as a C symbol, instead of trying to convert everything.






share|improve this answer



























  • That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

    – 4nti7rust
    Mar 27 at 13:33












  • Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

    – artcorpse
    Mar 27 at 15:44











  • No error related to _foo, but I suspect this include to have mixed c and cpp header files.

    – 4nti7rust
    Mar 27 at 15:46



















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3















I want to use that enum in a C file. How can I do that?




Enum concept in C++ originates from C, so only thing you have to do is to isolate definition this enum from pure cpp API which is not known to C (remember about name mangling, see below).



Since C do not know in class/struct enums you can't use them. You have to define global scope enumeration or create such enumeration which will map C++ specific enumeration.



So create separate header file where shared API should be located. Do something like this:



// shared C, C++ header
#ifdef __cplusplus
extern "C"

#endif

enum YourMagicEnum
YourMagicEnumAValue,
YourMagicEnumBValue,
YourMagicEnumCValue,
;

void someFunction(YourMagicEnum x);

#ifdef __cplusplus
// extern "C"
#endif


Now this extern "C" is needed only for functions to disable name mangling (in C++ you can do function overloads, so compiler generates names which contain arguments type information).



When defining such function it should also have the extern "C" in front of that definition.



And remember in that header only C specific features and functions can be placed.



Also remember that VLA (Variable-length array) is in C standard, but not in C++ standard (most compiler support VLA for C++).



For more information see this page.






share|improve this answer



























  • I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

    – 4nti7rust
    Mar 27 at 13:37











  • There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

    – Marek R
    Mar 27 at 13:40











  • I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

    – 4nti7rust
    Mar 27 at 13:44











  • only some script which will parse original file and generate respective C header.

    – Marek R
    Mar 27 at 13:54











  • Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

    – 4nti7rust
    Mar 27 at 14:02















3















I want to use that enum in a C file. How can I do that?




Enum concept in C++ originates from C, so only thing you have to do is to isolate definition this enum from pure cpp API which is not known to C (remember about name mangling, see below).



Since C do not know in class/struct enums you can't use them. You have to define global scope enumeration or create such enumeration which will map C++ specific enumeration.



So create separate header file where shared API should be located. Do something like this:



// shared C, C++ header
#ifdef __cplusplus
extern "C"

#endif

enum YourMagicEnum
YourMagicEnumAValue,
YourMagicEnumBValue,
YourMagicEnumCValue,
;

void someFunction(YourMagicEnum x);

#ifdef __cplusplus
// extern "C"
#endif


Now this extern "C" is needed only for functions to disable name mangling (in C++ you can do function overloads, so compiler generates names which contain arguments type information).



When defining such function it should also have the extern "C" in front of that definition.



And remember in that header only C specific features and functions can be placed.



Also remember that VLA (Variable-length array) is in C standard, but not in C++ standard (most compiler support VLA for C++).



For more information see this page.






share|improve this answer



























  • I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

    – 4nti7rust
    Mar 27 at 13:37











  • There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

    – Marek R
    Mar 27 at 13:40











  • I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

    – 4nti7rust
    Mar 27 at 13:44











  • only some script which will parse original file and generate respective C header.

    – Marek R
    Mar 27 at 13:54











  • Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

    – 4nti7rust
    Mar 27 at 14:02













3












3








3








I want to use that enum in a C file. How can I do that?




Enum concept in C++ originates from C, so only thing you have to do is to isolate definition this enum from pure cpp API which is not known to C (remember about name mangling, see below).



Since C do not know in class/struct enums you can't use them. You have to define global scope enumeration or create such enumeration which will map C++ specific enumeration.



So create separate header file where shared API should be located. Do something like this:



// shared C, C++ header
#ifdef __cplusplus
extern "C"

#endif

enum YourMagicEnum
YourMagicEnumAValue,
YourMagicEnumBValue,
YourMagicEnumCValue,
;

void someFunction(YourMagicEnum x);

#ifdef __cplusplus
// extern "C"
#endif


Now this extern "C" is needed only for functions to disable name mangling (in C++ you can do function overloads, so compiler generates names which contain arguments type information).



When defining such function it should also have the extern "C" in front of that definition.



And remember in that header only C specific features and functions can be placed.



Also remember that VLA (Variable-length array) is in C standard, but not in C++ standard (most compiler support VLA for C++).



For more information see this page.






share|improve this answer
















I want to use that enum in a C file. How can I do that?




Enum concept in C++ originates from C, so only thing you have to do is to isolate definition this enum from pure cpp API which is not known to C (remember about name mangling, see below).



Since C do not know in class/struct enums you can't use them. You have to define global scope enumeration or create such enumeration which will map C++ specific enumeration.



So create separate header file where shared API should be located. Do something like this:



// shared C, C++ header
#ifdef __cplusplus
extern "C"

#endif

enum YourMagicEnum
YourMagicEnumAValue,
YourMagicEnumBValue,
YourMagicEnumCValue,
;

void someFunction(YourMagicEnum x);

#ifdef __cplusplus
// extern "C"
#endif


Now this extern "C" is needed only for functions to disable name mangling (in C++ you can do function overloads, so compiler generates names which contain arguments type information).



When defining such function it should also have the extern "C" in front of that definition.



And remember in that header only C specific features and functions can be placed.



Also remember that VLA (Variable-length array) is in C standard, but not in C++ standard (most compiler support VLA for C++).



For more information see this page.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 10:06

























answered Mar 27 at 9:59









Marek RMarek R

15.1k3 gold badges30 silver badges81 bronze badges




15.1k3 gold badges30 silver badges81 bronze badges















  • I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

    – 4nti7rust
    Mar 27 at 13:37











  • There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

    – Marek R
    Mar 27 at 13:40











  • I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

    – 4nti7rust
    Mar 27 at 13:44











  • only some script which will parse original file and generate respective C header.

    – Marek R
    Mar 27 at 13:54











  • Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

    – 4nti7rust
    Mar 27 at 14:02

















  • I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

    – 4nti7rust
    Mar 27 at 13:37











  • There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

    – Marek R
    Mar 27 at 13:40











  • I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

    – 4nti7rust
    Mar 27 at 13:44











  • only some script which will parse original file and generate respective C header.

    – Marek R
    Mar 27 at 13:54











  • Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

    – 4nti7rust
    Mar 27 at 14:02
















I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

– 4nti7rust
Mar 27 at 13:37





I will probably end up doing that, but I have only one C file using this class, everything else is C++ and I wanted to keep everything inside class namespace to avoid all my enum definition to be global (I really have a lot of them and it will quickly be very messy).

– 4nti7rust
Mar 27 at 13:37













There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

– Marek R
Mar 27 at 13:40





There are no namespaces in C or neither classes, so you can't use them if you need access API form C.

– Marek R
Mar 27 at 13:40













I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

– 4nti7rust
Mar 27 at 13:44





I understand that, but is there a way to define a C type that is a copy of the one inside my class ?

– 4nti7rust
Mar 27 at 13:44













only some script which will parse original file and generate respective C header.

– Marek R
Mar 27 at 13:54





only some script which will parse original file and generate respective C header.

– Marek R
Mar 27 at 13:54













Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

– 4nti7rust
Mar 27 at 14:02





Ugly. Ok, I think I will just do it manually, hopefully when the code will evolve to more C++ we will get rid of it. I will wait a few more hours to see if someone else comes with another workaround, else I think your answer is the one that makes more sense. If you could rewrite your answer with the same namings as my example, and show how to include this type declaration back to the class, that would make it perfect !

– 4nti7rust
Mar 27 at 14:02













1














Your Try2 is pretty close to a solution. Try to move the include outside extern "C".
I usually just mark each function individually:



extern "C" void foo() 

...



This has the benefit of just exporting the one symbol as a C symbol, instead of trying to convert everything.






share|improve this answer



























  • That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

    – 4nti7rust
    Mar 27 at 13:33












  • Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

    – artcorpse
    Mar 27 at 15:44











  • No error related to _foo, but I suspect this include to have mixed c and cpp header files.

    – 4nti7rust
    Mar 27 at 15:46















1














Your Try2 is pretty close to a solution. Try to move the include outside extern "C".
I usually just mark each function individually:



extern "C" void foo() 

...



This has the benefit of just exporting the one symbol as a C symbol, instead of trying to convert everything.






share|improve this answer



























  • That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

    – 4nti7rust
    Mar 27 at 13:33












  • Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

    – artcorpse
    Mar 27 at 15:44











  • No error related to _foo, but I suspect this include to have mixed c and cpp header files.

    – 4nti7rust
    Mar 27 at 15:46













1












1








1







Your Try2 is pretty close to a solution. Try to move the include outside extern "C".
I usually just mark each function individually:



extern "C" void foo() 

...



This has the benefit of just exporting the one symbol as a C symbol, instead of trying to convert everything.






share|improve this answer















Your Try2 is pretty close to a solution. Try to move the include outside extern "C".
I usually just mark each function individually:



extern "C" void foo() 

...



This has the benefit of just exporting the one symbol as a C symbol, instead of trying to convert everything.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 9:50

























answered Mar 27 at 9:44









artcorpseartcorpse

1904 silver badges7 bronze badges




1904 silver badges7 bronze badges















  • That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

    – 4nti7rust
    Mar 27 at 13:33












  • Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

    – artcorpse
    Mar 27 at 15:44











  • No error related to _foo, but I suspect this include to have mixed c and cpp header files.

    – 4nti7rust
    Mar 27 at 15:46

















  • That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

    – 4nti7rust
    Mar 27 at 13:33












  • Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

    – artcorpse
    Mar 27 at 15:44











  • No error related to _foo, but I suspect this include to have mixed c and cpp header files.

    – 4nti7rust
    Mar 27 at 15:46
















That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

– 4nti7rust
Mar 27 at 13:33






That is a good proposal, but sadly I have linking errors when doing that (Undefined reference and multiple definition). Do you know what could create that (big_hugly_include.h is really full of ****) ? I have added try 3 in my question.

– 4nti7rust
Mar 27 at 13:33














Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

– artcorpse
Mar 27 at 15:44





Unfortunately I don't think I can give too much insight without learning about this big_hugly_include.h. It sounds like a C++ header file, so it's most probably important for it to be outside the extern "C" block. The two types of errors you're mentioning sound like linking errors, so some of your other cpp files must be mismatched. Are you getting any errors related to "_foo"?

– artcorpse
Mar 27 at 15:44













No error related to _foo, but I suspect this include to have mixed c and cpp header files.

– 4nti7rust
Mar 27 at 15:46





No error related to _foo, but I suspect this include to have mixed c and cpp header files.

– 4nti7rust
Mar 27 at 15:46



Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현