Including non-standard C headers in C++
I needed to include a few c headers ( non standard header files ) in my C++ code to be compiled by gcc. The C header (foo.h) has support for :
#ifdef __cplusplus
extern "C" {
#endif
and similarly at the end for }
. The c++ code has the include "foo.h"
I believe I should be able to just include the header (foo.h) and create instances of structs defined in the .h file.
I am not able to compile the source code. It seems like the compiler looks at the c code as if it were c++ code. I see error such as
error: expected constructor, destructor or type conversion before "("
Did I do something wrong ? I took advise from : http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
What else do i need to do, to tell the c++ compiler "expect and compile as c code" ?
Thanks for all your replies !
My problem was i had not included all the needed header files / in the right order . I am all set.
精彩评论