Integration of C and C ++ in Linux-general Linux technology-Linux programming and kernel information. For details, refer to the following section. Recently, we encountered a technical problem that was quite scratching our head. The code of our customer company in Boston was both C ++ and C. As an outsourcing company, we need to integrate our C ++ code with them. The original integration solution was that our C ++ was mixed with their C ++, in this way, I did not Touch any C integration winter. At that time, I had fixed this problem in Boston, but before the business trip back, the customer proposed to optimize the system efficiency, this means that we want to reuse their C code more, so that the tasks that integrate C and C ++ are gradually put on the agenda.
There are a lot of Chinese and English articles on the Internet discussing this aspect, but I don't feel very comprehensive. When I use these methods for some time, I don't provide a comprehensive and systematic solution to the problem, I picked one of them: Workshop
The first three parts are popular science. You can leave them alone. The last part describes the two examples of C ++ Calling C and C Calling C ++. They are very useful. Let me summarize:
(1) problems with C ++ Calling C:
In the File of C ++, add the header File of C. Generally, you need to add extern "C", but this is not an iron law. I will talk about this issue later, I think this is sometimes miserable. We recommend that you add the _ cplusplus macro to the original sample, for example: