Is extern “C” only required on the function declaration?

The ‘extern “C”‘ should not be required on the function defintion as long as the declaration has it and is already seen in the compilation of the definition. The standard specifically states (7.5/5 Linkage specifications): A function can be declared without a linkage specification after an explicit linkage specification has been seen; the linkage explicitly …

Read more

Call a C function from C++ code

Compile the C code like this: gcc -c -o somecode.o somecode.c Then the C++ code like this: g++ -c -o othercode.o othercode.cpp Then link them together, with the C++ linker: g++ -o yourprogram somecode.o othercode.o You also have to tell the C++ compiler a C header is coming when you include the declaration for the …

Read more