开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜