[*]A C header file with a few extern functions declared
[*]A C++ source file with those functions defined
[*]Compile the C++ source into a shared library
In a C source file use the functions declared in C header Связываясь против. Вещи начинают работать
с неназванным Namepsase. < /P>
Вот мой пример файла: < /p>
Код: Выделить всё
c_sample.hКод: Выделить всё
#include "stddef.h"
extern void hello(void);
extern void bye(void);
< /code>
cpp_sample.ccКод: Выделить всё
#include
#include "c_sample.h"
extern "C" {
void hello(void) { std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79544030/anonymous-namespace-and-extern-c-linkage-question[/url]
Мобильная версия