www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - importC - how to use more effectively?

reply WebFreak001 <d.forum webfreak.org> writes:
I just first time used importC in a prototype project I just 
worked on. I used it to just import `libevdev.h` on linux to 
register a custom input device / make a simple userspace input 
driver.

Now libevdev comes with two header files: libevdev.h and 
libevdev-uinput.h

Q1) Since libevdev-uinput.h included libevdev.h, I could simply 
import that to get everything. What would I do in more complex 
libraries that are composed of multiple header files though?

I had a small problem: linux/input.h was included, but not found 
/ not properly processed, so I had to manually look that up in 
the correct architecture folder of my linux distro.

What I now did was copy-pasting the files both from libevdev and 
from linux/input.h from my local system into my project 
directory, running `gcc -E` and manually cleaning up things, so 
that stuff like `u8` existed. (using a package in D that I would 
`__import` to include compat things)

Q2) How would I do this without manually copying and editing the 
header files, so that it would work on other people's machines as 
well, using their local headers?

---

I'm quite a fan of how easy it was using importC to get libevdev 
running in my custom program and quickly making a basic custom 
input device, exactly with the same syntax and functions as in C, 
but this only really seems to work inside the prototyping phase. 
What would be the next steps if I wanted to make e.g. a libevdev 
wrapper to put on DUB?

Q3) Would generating D code from importC be possible for this?
Feb 22 2023
parent Andrea Fontana <nospam example.org> writes:
On Wednesday, 22 February 2023 at 15:00:56 UTC, WebFreak001 wrote:
 I just first time used importC in a prototype project I just 
 worked on. I used it to just import `libevdev.h` on linux to 
 register a custom input device / make a simple userspace input 
 driver.
A suggestion: try tcc as preprocessor. It works better than gcc for importc. Andrea Fontana
Feb 22 2023