Skip to content

Linker is invoked from unexpected directory #7146

@gridbugs

Description

@gridbugs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions