You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But regardless, my executable isn't public, can I still somehow run it? I can make it public, but it seems annoying to have to make executables just to run them.
It didn't exist, thanks for the hint. My library was actually public, but i still ran into that error. Looks like I still needed to build the native target to run the bytecode executable. Note sure if that's expected.
I fail to load from utop a library defined with a c-stubs. Utop say "Cannot load required shared library. Cannot open shared object file: No such file or directory. ".
Indeed, the shared library is installed by jbuilder/opam in a directory named stubslibs instead of stublibs.
$ jbuilder install
# opam-version 1.2.2
# os linux
...
_build/install/default/lib/stublibs/dllkyoto_stubs.so => /home/didier/.opam2/4.04.2+flambda/lib/stubslibs/dllkyoto_stubs.so
...
As @trefis notes, it's entirely to do with a very long-standing bug in opam-installer. You can fix it locally by updating to opam2 beta 4, but I think this makes a very strong case for having jbuilder install process the .install itself.
Note that installs via opam should be unaffected - there is (intentional) code duplication between opam and opam-installer, so as long as your opam file doesn't incorrectly try to run jbuilder install then opam packages are fine.
I hit this issue using ctypes + mdx. The mdx stanza creates `mdx-gen.ml, but mdx-gen.bc fails to run. It dlopens the stub fine, but the dynamic linked library itself is not found (missing symbol).
We're still running into this (see @Khady's post above; we have a pretty pervasive hack involving CAML_LD_LIBRARY_PATH-setting in a bunch of our internal binaries ...)
Unfortunately, that doesn't seem to be helpful in the case mentioned by @frejsoya — I can't feed CAML_LD_LIBRARY_PATH to the mdx_gen.bc invocation:
$ export CAML_LD_LIBRARY_PATH="$scriptdir/../../_build/default/backend/ahrefskit:$CAML_LD_LIBRARY_PATH"
$ dune runtest --verbose... SNIP ...Running[1]: (cd _build/default/backend/COMPONENT/client && ./mdx_gen.bc using_ppx.mld) > _build/default/backend/COMPONENT/client/.mdx/using_ppx.mld.correctedFile "backend/COMPONENT/client/dune", line 36, characters 0-67:36 | (mdx37 | (files using_ppx.mld)38 | (libraries COMPONENT.ppx_COMPONENT))Command [1] got signal ABRT: $ (cd _build/default/backend/COMPONENT/client && ./mdx_gen.bc using_ppx.mld) > _build/default/backend/COMPONENT/client/.mdx/using_ppx.mld.correctedFatal error: cannot load shared library dllahrefskit_stubs_stubsReason: dllahrefskit_stubs_stubs.so: cannot open shared object file: No such file or directory
Unfortunately, the thing-under-test is a ppx; which doesn't accept (modes byte_complete); and (ocamlc_flags (-custom)) is no more helpful:
$ dune runtest... SNIP ...File "backend/COMPONENT/client/dune", line 36, characters 0-67:36 | (mdx37 | (files using_ppx.mld)38 | (libraries COMPONENT.ppx_COMPONENT))/usr/bin/ld: cannot find -lmysql_stubs/usr/bin/ld: cannot find -lmurmur3_stubs/usr/bin/ld: cannot find -lmariadb_stubs/usr/bin/ld: cannot find -lctypes_stubs... SNIP .../usr/bin/ld: cannot find -lcurl_stubscollect2: error: ld returned 1 exit statusFile "_none_", line 1:Error: Error while building custom runtime system
Is there any workaround to this that will function in a ppx-rewriter binary, when using (mdx …)? /=
It seems at the moment we give an error message like this:
Reproduction case for https://github.com/ocaml/dune/issues/108
$ cat > dune-project <<EOF
> (lang dune 3.19)
> (package (name foo))
> EOF
$ cat > dune <<EOF
> (executable
> (public_name hello_world)
> (modes byte)
> (foreign_stubs
> (language c)
> (names hw)))
> EOF
$ cat > hello_world.ml <<EOF
> external print_hello : unit -> unit = "caml_print_hello"
>
> let () = print_hello ()
> EOF
$ cat > hw.c <<EOF
> #include <stdio.h>
> #include <caml/mlvalues.h>
>
> CAMLprim value caml_print_hello(value unit)
> {
> printf("Hello\n");
> return Val_unit;
> }
> EOF
$ dune exec -- ./hello_world.bc
File "dune", lines 1-6, characters 0-98:
1 | (executable
2 | (public_name hello_world)
3 | (modes byte)
4 | (foreign_stubs
5 | (language c)
6 | (names hw)))
Error: Pure bytecode executables cannot contain foreign stubs.
Hint: If you only need to build a native executable use "(modes exe)".
[1]
I suppose we could close this issue as its not something we explicitly support. If we were to support such a feature (how, I have no idea) it would be a new feature request.
Activity
rgrinberg commentedon May 30, 2017
Hm, but
CAML_LD_LIBRARY_PATHseems correct to me:opam switch is supposed to set it right?
But regardless, my executable isn't public, can I still somehow run it? I can make it public, but it seems annoying to have to make executables just to run them.
rgrinberg commentedon May 31, 2017
Hmm, I'm still unable to run the bytecode binary this way. Even after setting CAML_LD_LIBRARY_PATH to what
jbuilder execwould. See:Seems like CAML_LD_LIBRARY_PATH is set correctly here but the bytecode isn't running.
rgrinberg commentedon May 31, 2017
It didn't exist, thanks for the hint. My library was actually public, but i still ran into that error. Looks like I still needed to build the native target to run the bytecode executable. Note sure if that's expected.
rgrinberg commentedon May 31, 2017
OK, then I think leaving a note about the current situation is enough. This isn't an issue in practice anyway.
Add a note about byte-code executables (#108)
didier-wenzek commentedon Sep 12, 2017
I experienced a related issue.
I fail to load from utop a library defined with a c-stubs. Utop say "Cannot load required shared library. Cannot open shared object file: No such file or directory. ".
Indeed, the shared library is installed by jbuilder/opam in a directory named stubslibs instead of stublibs.
trefis commentedon Sep 13, 2017
I ran into the same issue a few days ago.
I believe this might be related to ocaml/opam@718d619 .
Which version of opam/opam-installer are you using?
(ping @AltGr)
dra27 commentedon Sep 13, 2017
As @trefis notes, it's entirely to do with a very long-standing bug in opam-installer. You can fix it locally by updating to opam2 beta 4, but I think this makes a very strong case for having
jbuilder installprocess the .install itself.Note that installs via opam should be unaffected - there is (intentional) code duplication between opam and opam-installer, so as long as your opam file doesn't incorrectly try to run
jbuilder installthen opam packages are fine.17 remaining items
vsiles commentedon Mar 27, 2019
Hi ! I just had the same issue (I baked a toy example in https://github.com/vsiles/dune-debug-test)
The two workarounds I got were:
LD_LIBRARY_PATHon invocation, but that's not satisfying-customwhen building with ocamlc (ocamlc_flags (:standard -custom)) which creates a viable .bc fileFix tests following addition of C code in InferStdlib
thautwarm commentedon May 18, 2020
@vsiles Thank you! I searched everywhere for a thousand years and you saved my life!
vsiles commentedon May 19, 2020
Thanks for this info. Do you know in which version
-customhas been deprecated (we are lagging quite a bit, so I'll have to update at some point :D)frejsoya commentedon Sep 13, 2023
I hit this issue using ctypes + mdx. The mdx stanza creates `mdx-gen.ml, but mdx-gen.bc fails to run. It dlopens the stub fine, but the dynamic linked library itself is not found (missing symbol).
Mac OSX
ELLIOTTCABLE commentedon Dec 5, 2023
We're still running into this (see @Khady's post above; we have a pretty pervasive hack involving
CAML_LD_LIBRARY_PATH-setting in a bunch of our internal binaries ...)Unfortunately, that doesn't seem to be helpful in the case mentioned by @frejsoya — I can't feed
CAML_LD_LIBRARY_PATHto themdx_gen.bcinvocation:Unfortunately, the thing-under-test is a ppx; which doesn't accept
(modes byte_complete); and(ocamlc_flags (-custom))is no more helpful:Is there any workaround to this that will function in a ppx-rewriter binary, when using
(mdx …)? /=frejsoya commentedon Dec 5, 2023
@ELLIOTTCABLE i made this pr #8784 some time ago. Which might be related. I should have followed up on it :)
For non-installed shared libraries, at build time and + avoiding global env flags, it is possible to use relative paths to the binary with
rpath(Runtime-paths). Reference for how CMAKE does this https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handlingjoelreymont commentedon Jun 13, 2025
Is this still an unresolved issue?
Alizter commentedon Jun 13, 2025
It seems at the moment we give an error message like this:
I suppose we could close this issue as its not something we explicitly support. If we were to support such a feature (how, I have no idea) it would be a new feature request.