Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include statements included in target header files #87

Open
matanox opened this issue Jun 17, 2020 · 3 comments
Open

Include statements included in target header files #87

matanox opened this issue Jun 17, 2020 · 3 comments
Labels
need-info Need more information to proceed.

Comments

@matanox
Copy link

matanox commented Jun 17, 2020

This is a usage / feature question which I hope is trivial to answer. When the header file which we unleash the tool on contains #include statements itself, is it currently supported to seamlessly generate also for those referenced header files?

For example:

Header file XKBlib.h (/usr/include/X11/XKBlib.h) will typically contain the following includes:

#include <X11/Xlib.h>
#include <X11/extensions/XKBstr.h>

Unless I'm experiencing a very specific bug, by plainly running the tool on this header file, I think that these referenced header files will not be processed.

Rather I will need to manually follow the chain of includes contained within the header file, and invoke this tool on each of them, in order to get all the symbols of the library of interest ready for ctypes use in python (I mean the library of which XKBlib.h is the "core" include file for, if this kind of naive relationship typically makes sense). Put differently, unlike the C compiler/s, this tool will not seamlessly follow referenced headers.

I am happy to learn whether this is a feature request or already implemented.

Or maybe it's uncommon for libraries to require the upstream user code to directly use symbols from nested header files and hence doesn't make sense (?!).

Thanks!

@matanox
Copy link
Author

matanox commented Jun 17, 2020

I'm seeing the -I option, but I think it's not exactly the same or just doesn't help getting the referenced header files processed, in my case.

@Alan-R
Copy link
Collaborator

Alan-R commented Aug 1, 2021

Not certain if this is behaving the way you stated or not. I'm fairly certain that I have code which works the way you want it to work, not the way you describe it as behaving.
Can you give a specific example (ideally on Linux) with the specific options (like -I) you included with the output you got, along with the output you expected.

The default system header files occur in wildly different places on different platforms and compilers - and they change over time. It is necessary to include -I directories for all the places you expect headers to be parsed.

@Alan-R Alan-R added the need-info Need more information to proceed. label Aug 1, 2021
@mara004
Copy link
Contributor

mara004 commented Dec 16, 2023

To the OP: yes, all include statements should be expanded by the C preprocessor called by ctypesgen, but you will have to either pass the indirect headers to ctypesgen directly OR use --all-headers OR explicit include rules, AND add all libraries plus their directories to the ctypesgen cmd to expose e.g. X11 API functions.
If you don't, only direct dependencies like structs and typedefs get pulled into the output.

This branch of ctypesgen has that multilib support, but internally it's a bit of a messy matter IMHO.
Often it may be cleaner to create an independent binding to e.g. X11 first, and then use -m / --link-modules to use symbols from that binding.

Ctypesgen cannot traverse the dependency tree and create separate linked bindings to different libs automatically.
Similar to how C compilers can't automatically build dependency libraries.

See also #86 (comment) and pypdfium2-team#1 for considerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-info Need more information to proceed.
Projects
None yet
Development

No branches or pull requests

3 participants