Skip to content

SAOC 2026: fix #20152: ImportC: keep a C file in one object with -lib - #23904

Draft
niy-ati wants to merge 1 commit into
dlang:masterfrom
niy-ati:fix20152-c-lib-static-symbols
Draft

niy-ati wants to merge 1 commit into
dlang:masterfrom
niy-ati:fix20152-c-lib-static-symbols

Conversation

@niy-ati

@niy-ati niy-ati commented Sep 22, 2026

Copy link
Copy Markdown

Fixes #20152.

A library built with dmd -lib from a C file did not link. Each function was written into its own archive member (the multiobj split), so it could not reach the static variables and functions of its own C file, and linking against the library failed with undefined reference.

A C file is one translation unit, so it is no longer split for -lib. This also affects #22153's own regression test: the library it builds did not link either, on Linux or Windows, since that test only checked that the library compiled.

Test: dshell/issue20152.d, builds the library and links a consumer against it.

Part of SAOC 2026, ImportC: Zero-Wrapper Integration for Production-Grade C Libraries.

With -lib every function was written to its own archive member, so it could not
reach the static variables and functions of its C file and the library failed to
link with undefined references. A C file is one translation unit, so it is no
longer split.

Related to dlang#20152. The library built from compilable/fix22153.c did not link
either. The new test builds a library and links it.
@thewilsonator thewilsonator added the Feature:ImportC Pertaining to ImportC support label Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:ImportC Pertaining to ImportC support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImportC, forward referenced static functions, and -lib

2 participants