CxxCall.jl
CxxCall.jl copied to clipboard
Error when running example
Hi, i tried running your example on the readme page and got the following error:
ERROR: UndefVarError: mylib not defined
I was wondering if you could provide a complete example on how to sort a Julia string vector using c++ std::sort?
Thank you
Hi @gitboy16 you are right, docs are currently lacking. Meantime I recommend looking at the tests. I would start with hello world, does that work locally for you?
For the std::sort I can help with that, but it is already a bit advanced. The issue is that julia strings != C++ strings and there are multiple ways to deal with this. I suggest you try to sort a list of Float64 first and then we can look into the string example?
Hi, thanks for the feedback. I manage to run the hello example in your test folder but I had to change it a little bit.
I had the following error:
run(`g++ -shared -fPIC $(filepath) -o $libpath`)
clang-13: error: unsupported option '-fPIC' for target 'x86_64-w64-windows-gnu'
I removed the -fPIC and everything worked well.
I will try to sort float64 and let you know. Thank you.
I think I am going to need your help to get std::sort to work on a vector. 😅
Sure I would try something like this:
@cxx lib function unsafe_sort!(first::Ptr{Float64}, last::Ptr{Float64})::Cvoid
...
end
function sort!(v::Vector{Float64}
GC.@preserve v begin
unsafe_sort!(...)
end
end
Sorry I did not manage to make it work. I think I am very far from understanding how things work and from your level of knowledge.
Sorry I did not manage to make it work. I think I am very far from understanding how things work and from your level of knowledge.
Sure generally speaking if a problem is too hard for me to solve directly, I try to solve a simpler subproblem first. Often that subproblem is still too hard, so I slice it down again. This may require a few iterations, until things are simple enough. So here I would recommend calling C code instead of C++ first. Don't use any packages, just ccall. For instance, you could write a simple C function that fills an array with zeros and try to call it from julia.