ocaml / ocaml/dune

Linker is invoked from unexpected directory

Open
#7,146 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build c-bindings
Dominant language
OCaml
Stars
1.9k
Forks
500
Avg merge
15h 21m
Merged PRs (30d)
277

Description

Expected Behavior

If a library specifies custom linker flags in (c_library_flags ...) which reference files relative to the directory containing the dune file, those files should be discoverable by the linker. For example, if I have a project with a static library src/libfoo.a and src/dune is

(library
 ...
 (c_library_flags :standard -lfoo -L.))

...or...

(library
 ...
 (c_library_flags :standard -lfoo -L%{project_root}/src))

...the linker should be able to find the archive libfoo.a.

Actual Behavior

The linker can't find the library: cannot find -lfoo: No such file or directory. This is because the linker is not invoked from the directory containing the dune file, and %{project_root} resolves to a relative path (relative to the directory containing the dune).

Reproduction

Specifications

  • Version of dune (output of dune --version): 3.7
  • Version of ocaml (output of ocamlc --version): 4.14.0
  • Operating system (distribution and version): NixOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducing test in PR #7147 and the testing guidance in doc/hacking.rst. Verify the relative linker paths described in the issue, then confirm that the linker can discover libfoo.a from the directory containing the dune file.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.