Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C code from C++ using autotools

Tags:

c++

c

linker

I am writing a (my first) C++ class on top of some code written in C, but I can only get the C++ to compile by declaring the C functions in a extern block. My project uses autotools; is there any way to automate this process so I don't have to maintain two header files?

like image 986
drkatz Avatar asked Feb 08 '09 21:02

drkatz


People also ask

What is Autotools configure?

Autotools configurationThis file is used by autoconf to create the configure shell script that users run before building. The file must contain, at the very least, the AC_INIT and AC_OUTPUT M4 macros.

How do I use autoconf?

To create a configure script with Autoconf, you need to write an Autoconf input file configure.ac (or configure.in ) and run autoconf on it. If you write your own feature tests to supplement those that come with Autoconf, you might also write files called aclocal. m4 and acsite. m4 .

What does Autogen SH do?

The autogen.sh script generates the configure script (from configure.ac , using autoconf) and any files it needs (like creating Makefile.in from Makefile.am using automake).


1 Answers

Use a extern block inside a #ifdef in C codes header files

Start of header files

#ifdef __cplusplus
extern "C" {
#endif

...and at end of the header files

#ifdef __cplusplus
}
#endif

This way it will work for being included in both C and C++ sources

like image 95
epatel Avatar answered Oct 26 '22 23:10

epatel