Skip to content
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

Packaging a library with extra_objects #10466

Open
Hirrolot opened this issue Apr 29, 2024 · 0 comments
Open

Packaging a library with extra_objects #10466

Hirrolot opened this issue Apr 29, 2024 · 0 comments

Comments

@Hirrolot
Copy link
Contributor

(This is a continuation of my attempt to use a library with foreign C code.)

Run dune init proj --kind=library foo. Put the following support.c file in lib/:

#include <stdio.h>

void foo(void) {
    puts("foo");
}

lib/dune must look as follows:

(library
 (public_name foo)
 (name foo)
 (libraries ctypes.foreign)
 (extra_objects support))

(rule
 (targets support.o)
 (deps support.c)
 (action
  (run ocamlopt %{deps})))

lib/Foo.ml must be:

open Ctypes
open Foreign

let test = foreign "foo" (void @-> returning void)

Type dune build && dune install.

Then create a new project with dune init proj --kind=executable test with the following bin/dune:

(executable
 (public_name test)
 (name main)
 (libraries test foo))

and the following bin/main.ml:

open Foo

let () = test ()

Type dune exec test and see the following error:

File "bin/dune", line 3, characters 7-11:
3 |  (name main)
           ^^^^
/usr/bin/ld: cannot find lib/support.o: No such file or directory
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

Is there a way to tell Dune to link support.o with the executable? If I call Foo.test from within foo's tests, everything seems to work fine.

Specifications

$ dune --version
3.15.0
$ ocamlc --version
5.1.2+dev0-2023-12-7

My OS is Ubuntu 22.04 jammy (x86_64 Linux 6.5.0-28-generic).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant