There you can do different things.
You can rewrite it to C. Without actually looking at the code, I don't know how many problems there will be. A lot of C ++ code is just C with several add-ons, and some heavily use templates and overloaded functions, etc.
If you do not, you need to communicate well with C. This means providing an interface for C and its environment with extern "C"{ ... } , so the C ++ compiler will know to make the interface C-compatible. Again, without knowing something from the C ++ code, I canβt say how much this will work. You will need a shell for any of the following solutions.
You can make this a C ++ project, merge each C file with extern"C" { ... } and just link it. If you have C ++ files, the whole compilation should be C ++.
You can create a separate library that you can link to.
What you cannot do is compile C and C ++ with the C main () function or the C compiler. C ++ is more demanding and requires more from the main () function.
You can always try recompiling the C files that you use as C ++ and wrap the .h files for libraries in extern "C" { ... } . A well-written C90 is not that far from legal C ++ (although the C99 standard has moved away from it), and the compiler will note any conversion problems you find.
Which one is the best idea for you depends on questions such as: How easy is it to convert code to C ++? How easy is it to write a C shell for the C ++ functionality you want? How many changes do you want to make to the C code? How familiar are you with creating the Linux library?
source share