Skip to content
New issue

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

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

Already on GitHub? # to your account

importing #define numerical constants to Julia #116

Open
hros opened this issue Nov 8, 2022 · 3 comments
Open

importing #define numerical constants to Julia #116

hros opened this issue Nov 8, 2022 · 3 comments

Comments

@hros
Copy link

hros commented Nov 8, 2022

is it possible to import #define NAME val from a C header file to Julia such that NAME = val?

@krrutkow
Copy link
Member

krrutkow commented Nov 8, 2022

In general it is not possible without writing a very large amount of code. But some of the more trivial conversions (e.g. numerical constants) are attempted by CBinding.

julia> module Macros
         using CBinding

         c``

         c"""
           #define NUMBER 1234
         """j
       end
Main.Macros

julia> Macros.@NUMBER
1234

@hros
Copy link
Author

hros commented Nov 8, 2022

fantastic. It is working for me.
Edit: actually, it is working only for some macro constants. in my project (see link below), XXH3_SECRET_SIZE_MIN is recognized but XXH_SECRET_DEFAULT_SIZE is not.

One more thing, if you could have a look at the xxh project (referenced in a previous issue):
I am trying to wrap one last function, and for some reason it is not being exposed by CBinding.
The function is XXH3_generateSecret (and its variant: XXH3_generateSecret_fromSeed).
The function prototype looks like the other functions which are detected and exported by CBinding.

Naturally, I can create a custom wrapper for the function, but it would be a shame to load the library with Libdl just for this function

@notinaboat
Copy link

notinaboat commented Nov 28, 2022

Related: using the cling interpreter to resolve #define values... JuliaInterop/Clang.jl#309 (comment)

Cling is now available as a jll: https://github.com/JuliaBinaryWrappers/Cling_jll.jl
Currently working on Linux and on intel macOS. Detail here: https://github.com/JuliaPackaging/Yggdrasil/blob/master/C/Cling/build_tarballs.jl#L102-L117

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants