-
Notifications
You must be signed in to change notification settings - Fork 17
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
Upgrade to Clipper2 #50
base: master
Are you sure you want to change the base?
Conversation
So, now that the PR is open, I can start asking questions. Just a quick disclaimer: this is my first time working on wrapping a library. As I mentioned above, Clipper2_jll is now available, so I have started using it in the PR. I am now trying to figure out what the next steps should be. My attempt at the immediate next step was to check if I am able to call a function, e.g., Clipper2Lib::Area. However, this is what I get: julia> using Clipper2_jll
julia> @ccall libClipper2.Area()::Float32
ERROR: could not load symbol "Area":
dlsym(0x9be6cd80, area): symbol not found
Stacktrace:
[1] top-level scope
@ ./REPL[2]:1 Running
but I realised that However, from looking at the Yggdrasil build for Clipper v1 (here), it seems that another approach was taken: the C++ methods were wrapped in C, and then Julia calls the C wrapper methods. |
Okay, I've made a tiny bit of progress. From a Julia script, I was able to load the dynamic library and find the symbol for the Here is my test script: using Libdl
# Define the Point64 type
# http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/Point64.htm
struct Point64
X::Cint
Y::Cint
end
# Load the dynamic library
dll_handle = dlopen("/Users/henrique/.julia/artifacts/b2f80988615b762a0db5a74dbc8a5c94d752f255/lib/libClipper2.1.2.2.dylib")
# Retrieve the `Area` static function symbol
const AreaFunction = dlsym(dll_handle, :_ZN11Clipper2Lib4AreaEPNS_5OutPtE)
# `Area` function wrapper
function area(path::Vector{Point64})
return ccall(AreaFunction, Cdouble, (Ptr{Point64}, Csize_t), path, length(path))
end
# Create a path
path = [Point64(100, 50), Point64(10, 79), Point64(65, 2)]
# Calculate the area of that path
result = area(path)
# Close the dynamic library
dlclose(dll_handle) Currently, this script crashes at
I also had a look at Cxx.jl, but I am not planning to use it because of:
CxxWrap.jl seems like a better alternative anyway, but it also does seem like it would require a fair amount of work. At this point, I don't know if it would be better to use CxxWrap.jl or to just write a custom C wrapper similar to the cclipper.cpp for Clipper1. I spent some time trying to give the latter option a go, but I couldn't get BinaryBuilder.jl to build stuff locally with Oh, and I almost forgot to mention that another option could be to just use this already-existing C wrapper: https://github.com/geoffder/clipper2c. |
The simplest way is likely to use the already-existing C wrapper. This is what the Golang wrapper does. |
Are you referring to https://github.com/geoffder/clipper2c? After I had posted my messages above, I also found that the author provided a |
@ferrolho I just noticed this discussion. Would it be useful for you to have commit access to this repo (if you don't already)? |
That would be helpful if I resume working on this, but I haven't done it for over a year now. 😬 |
Yeah, I realized this is an old thread. Anyways, I invited you for commit access. |
Thanks! I've accepted the invite. |
Just leaving this here from the updated CI etc. This PR needs to update the API:
If there is a C Wrapper, we should try go the clang.jl route. |
Package version should only be bumped to the next minor version.
I am opening this draft PR to make Clipper2 available in Julia (and as a means of getting feedback). Once ready, this PR should resolve #49.
In a previous discussion with @SimonDanisch on Slack (here), we agreed to tag a new version in the existing Clipper.jl repository, rather than starting a new repository/package — so that's what I did.
The current status is that a Clipper2_jll for Clipper2
v1.2.2
has been built using BinaryBuilder.jl, and it is now available (see JuliaPackaging/Yggdrasil#7093). But that is pretty much it so far, though.