Skip to content

--linkage shared: a library reached through a dependency's export import is not on the consumer's link line (DSO missing from command line) #1031

Backlog

Description

@speak-agent

mcpp 2026.11.27.1, Linux x86_64, GCC 16.1. Three packages: a (a library), b (a library: export module b; export import a;), app (a program depending on b only, calling a function of a that b re-exports).

a/mcpp.toml      [package] name = "a" … [targets.a] kind = "lib"
a/src/a.cppm     export module a; export int answer();
a/src/a.cpp      module a; int answer() { return 42; }
b/mcpp.toml      [package] name = "b" … [targets.b] kind = "lib"   [dependencies] a = { path = "../a" }
b/src/b.cppm     export module b; export import a; export int twice();
b/src/b.cpp      module b; int twice() { return 2 * answer(); }
app/mcpp.toml    [targets.app] kind = "bin" main = "src/main.cpp"  [dependencies] b = { path = "../b" }
app/src/main.cpp import std; import b; int main() { std::println("{} {}", answer(), twice()); }

mcpp build (static) links and prints 42 84. mcpp pack --linkage shared --pkg-format dir builds liba.so and libb.so, then the program's link has -lb only:

… g++ @bin/app.rsp -o bin/app … -Lbin -Wl,-rpath,'$ORIGIN' -lb …
ld: obj/main.o: undefined reference to symbol '_ZW1a6answerv'
ld: …/bin/liba.so: error adding symbols: DSO missing from command line

main.o refers to a's symbols directly (the import of b makes a's interface visible, so the call is to a), and GNU ld does not take symbols from a library that is only another library's DT_NEEDED (--no-copy-dt-needed-entries, its default). Statically every archive of the graph is on the line, so this shows with shared linkage only.

Expected: the libraries of the modules a unit's imports re-export (export import, transitively) are on its image's link line, as its own direct dependencies are.

Found on a real graph (an application on an umbrella package that re-exports its parts: undefined reference to symbol omui::ui::base::register_base_components, libomui_ui_base…so: DSO missing from command line), after 2026.11.27.1's fix of mcpp#975 let the shared plan through.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions