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
Undefined symbol when using ctypes.foreign
#10461
Comments
It is also interesting to note that calling |
This comes from a confusion between dynamic loading and dynamic linking.
So the fact that it works in bytecode mode is more of an unintended side effect. NB: it's not really a Dune issue, if you compile manually with To fix this, you have several alternatives:
Thanks |
Thanks for your response. However, if I define |
What does the dune file look like? |
Take the project
With
and let () = Foo.test() After |
In that case, |
So Dune's approach is to link libraries dynamically if stubs are defined in |
Dune isn't really taking a decision for library authors here: it's calling
|
After some fiddling, I came upon this solution (
The object file |
Just to add a comment to @emillon's reply: when you define a library with C stubs, both static and dynamic versions of it are produced; one of the reasons for this is that while native executables are linked statically, bytecode executables need to load native libraries dynamically. |
Update: unfortunately, while my above solution works with tests, it doesn't work with other executable projects:
|
Run
dune init proj --kind=library foo
. Put the followingsupport.c
file inlib/
:lib/dune
must look as follows:lib/Foo.ml
must be:Type
dune build && dune install
.Then create a new project with
dune init proj --kind=executable test
with the followingbin/dune
:and the following
bin/main.ml
:Type
dune exec test
and see the following error:I expected the code to print
foo
and exit.Specifications
My OS is Ubuntu 22.04 jammy (x86_64 Linux 6.5.0-28-generic).
The text was updated successfully, but these errors were encountered: