-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix x86_64 ABI calling convention for structs with floats #105
Comments
And I make more testes with following code. struct comp
x::Cfloat
y::Cfloat
end
b = comp(2,3)
function ccall_op(x::comp)
return ccall((:op, libdir * "/" * libname * ".so"), comp, (comp,), x)
end
function ccall_op_1(x::complexx)
return ccall((:op, libdir * "/" * libname * ".so"), complexx, (complexx,), x)
end
function ccall_op(x::complexx)
return ccall((:op, libdir * "/" * libname * ".so"), comp, (complexx,), x)
end
|
This looks like it is an ABI incompatibility issue. There is no issue if the struct contains |
Could you give any idea how to work around? I need badly to bind a C project with Julia. Thanks. |
It would be possible to work around this by passing the struct parameters by pointer instead (this is also the work around needed if using a packed struct, as described JuliaLang/julia#45363 (comment)). This could be accomplished with a separate "shim" library or by using CBinding, such as: c"""
static inline complexx ptr_op(complexx *x) { return op(*x); }
"""wj Then (as you can see from your example) calling |
All right. Hope this bug will be fixed soon. Thank you for this great package! |
Tested with Julia 1.7.3, Ubuntu 22.04 |
|
I took a try without success. I updated c`-I$(incdir) -L$(libdir) -ltestc -Wl,-rpath=$(libdir)` When I execute the code, c"""
static inline complexx ptr_op(complexx * x) { return op(*x); }
"""wj I get this error: /usr/bin/x86_64-linux-gnu-ld: cannot find -ltestc: No such file or directory
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: LoadError: failed process: Process(`/home/ft/.julia/artifacts/ebac8bb0527804a315b230ade306d81c03684e58/tools/clang -x c -Wno-empty-translation-unit -w -O2 -fPIC -shared -o /home/ft/.julia/scratchspaces/d43a6710-96b8-4a2d-833c-c424785e5374/2eb3b37c-da49-4f49-af2a-ad223b197d31/libcbinding-2.so /tmp/jl_XtwHgg -I/home/ft/workspace/julia/testCBinding/src_c -L/home/ft/workspace/julia/testCBinding/src_c -ltestc -Wl,-rpath=/home/ft/workspace/julia/testCBinding/src_c`, ProcessExited(1)) [1] |
Seems not works for me. |
You are probably still using |
You are great! Now it works after change the lib name to |
@krrutkow I try to follow your instruction, but I get a problem. Please give a help ^_^.
testc.h file:
testc.c file:
Julia code:
Julia REPL:
Obviously, function 'op' does not works as expected. What's wrong with my code? Thank you!
Originally posted by @touchft in #103 (comment)
The text was updated successfully, but these errors were encountered: