neelance / ffi_gen

A generator for Ruby FFI bindings, directly from header files via LLVM's Clang compiler
MIT License
88 stars 26 forks source link

extern "C" definitions #6

Closed chriswailes closed 12 years ago

chriswailes commented 12 years ago

It doesn't look like FFI-Gen currently generates bindings for functions defined inside extern "C" {} blocks.

neelance commented 12 years ago

Possible, I'll look into it. Which header are you trying to process?

neelance commented 12 years ago

Sorry, but I can not reproduce your problem. ffi-gen is made for processing C-headers, so there shouldn't be an extern "C" {} (or it should be removed by the preprocessor).

chriswailes commented 12 years ago

I'm trying to generate C bindings for C++ code, which requires that I place some of my function declarations inside extern "C" {} blocks. You can find the code here.

neelance commented 12 years ago

Still, ffi-gen is meant to process C headers. You need to filter C++ stuff with preprocessor instructions, so that the processed header will look like a simple C header:

#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif

You may also look into the Core.h of LLVM, they have done the same thing there.

chriswailes commented 12 years ago

That's what I ended up doing and now everything is working fine. I'm glad that there was a solution that didn't involve a bunch of code duplication.