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

C++ support meta-issue #20

Closed
ihnorton opened this issue Mar 30, 2013 · 8 comments
Closed

C++ support meta-issue #20

ihnorton opened this issue Mar 30, 2013 · 8 comments
Labels

Comments

@ihnorton
Copy link
Collaborator

The wip_cpp branch is now sufficiently developed to enable this proof-of-concept demo:

https://github.com/ihnorton/VTK.jl

C++ method calls are supported as follows:

There are a lot of things to consider in developing this to the point where it is usable, so this issue and the c++ tag will be used to capture and discuss.

@timholy
Copy link
Collaborator

timholy commented Mar 30, 2013

Oh my---this is amazing. Clang's impact on the Julia ecosystem is huge and growing!

@ihnorton
Copy link
Collaborator Author

I haven't announced anything yet because I'm still not entirely convinced that this is sane :)

@ihnorton
Copy link
Collaborator Author

ihnorton commented Apr 3, 2013

Single inheritance by dispatching on the type of this* is now working:

https://github.com/ihnorton/VTK.jl/blob/5fd3b91/src/vtkRenderer.jl#L1-L9
https://github.com/ihnorton/VTK.jl/blob/5fd3b91e1/src/vtkViewport.jl#L17
https://github.com/ihnorton/VTK.jl/blob/5fd3b91e1b/examples/Sphere.jl#L32
(SetBackground is defined only for vtkRenderer parent class vtkViewport)

@ihnorton
Copy link
Collaborator Author

Automatic base class resolution has been implemented - imports superclasses automatically and constructs abstract type tree:
https://github.com/ihnorton/VTK.jl/blob/master/src/loadvtk.jl#L62-L103
https://github.com/ihnorton/VTK.jl/blob/2d0769877d52b034ecdd08f67d47aefa8ae923db/examples/Sphere.jl#L3-L11

@shaguniitb
Copy link

I want to try using this. Can someone guide me as to how I can use it. I checked out the wrap_cpp branch. But when I run the code,it still says:

ERROR: @Scall not defined

This is my code:

using Clang.cindex

t = ccall( (:clock, "libc"), Int32, ())
println(t)

a = @Scall((:main, "/home/shagun/Acads/learning_julia/libshared"), Uint8, ())
println("main was executed successfully")

@ihnorton
Copy link
Collaborator Author

This is still very rough right now, so be warned. A couple notes:

  1. To use this with most real C++ code, you have to set an extra compiler option so that callable stubs are generated for inline functions (otherwise they are elided because as expected, they are inline where needed!).
  2. The macros are not exported by Clang, but you can copy the latest macro code from load_vtk in the VTK.jl repository.
  3. However, the example you gave looks to be C-exported - there is no mangling - so this is macro is not necessary.
  4. Generally, you can call static C++ methods directly if you know the mangled name (see timholy/Cpp.jl)

I will try to clean this up soon and write some basic documentation so other people can hack on it.

@Keno
Copy link

Keno commented Aug 8, 2013

@ihnorton What's the current status?

@ihnorton
Copy link
Collaborator Author

ihnorton commented Aug 8, 2013

I've kept it up to date with Julia but otherwise haven't changed it very much in a while. The JIT'd vcalls still work. But I am giving up on the idea of doing this without any code generation, because I don't think it is reasonable to expect people to recompile a bunch of libraries they could get from apt-get, with weird (and hard-to-use) compiler options just to keep inline functions. So I'm working on generation of C-callable stubs.

melonedo pushed a commit to melonedo/Clang.jl that referenced this issue Jul 20, 2021
…request/fc0866d6

Change the return types of functions that returned nothing from None …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants