gcc - C/C++ compiling different parts of the program with different compilers -


i'm writing program in c++ requires call subroutine written in open source c program. c file called shd.c. (there no header file shd in program). c program compiles fine gcc compiler, , c++ program works fine when compiling g++ without reference c file.

however, g++ not c program, giving hundreds of errors , warnings when compile shd g++, , same problems when compiling the c++ program when includes c files.

as of now, way i'm including c file looks this:

extern "c"{ #include "shd" } 

anyway, think option here (correct me if i'm wrong) compile c , c++ files separately, different compilers. there way this? point out i'm using netbeans, if makes difference.

you can use gcc shd.c , g++ c++ files. there name mangling c++ function names, can't directly call (by name) c function c++ or c++ function c code. able call them, should declare function called extern "c".

there classic way of doing so: create shd.h c/c++ file declarations:

#ifdef __cplusplus   extern "c" { #endif  extern int shd_a(int, int); extern int shd_b(int, int); ...  #ifdef __cplusplus   } #endif 

and include both in shd.c , in c++ files.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -