Skip to content

No way to pass "-undefined dynamic_lookup" to Darwin linker for Zig sources? #8016

Description

@haberman

To build a native Python extension on Darwin, the option -undefined dynamic_lookup must be passed to the linker to indicate that unresolved symbols will be resolved at runtime.

More info here: Please use -undefined dynamic_lookup instead of -lpython or -framework Python to build Python extension modules on OS X

Otherwise you get errors like this:

cmd zig build-lib -dynamic -DPYHEXVER=50857456 --name pdfxt.cpython-38-darwin -I /Users/haberman/opt/anaconda3/include/python3.8 -I /usr/include pdfxt.zig
warning(link): unexpected LLD stderr:
Undefined symbol: zig-cache/o/90680a79ab7f51bd67f93a83b363da55/pdfxt.cpython-38-darwin.o: __PyArg_ParseTuple_SizeT
Undefined symbol: zig-cache/o/90680a79ab7f51bd67f93a83b363da55/pdfxt.cpython-38-darwin.o: _PyLong_FromLong
Undefined symbol: zig-cache/o/90680a79ab7f51bd67f93a83b363da55/pdfxt.cpython-38-darwin.o: _PyModule_Create2
symbol(s) not found

For zig cc it appears there is an option --allow-shlib-undefined that will achieve the desired effect.

zig/src/main.zig

Lines 1260 to 1263 in 9270aae

} else if (mem.eql(u8, arg, "--allow-shlib-undefined") or
mem.eql(u8, arg, "-allow-shlib-undefined"))
{
linker_allow_shlib_undefined = true;

zig/src/link/MachO.zig

Lines 781 to 784 in 9270aae

if (allow_shlib_undefined) {
try argv.append("-undefined");
try argv.append("dynamic_lookup");
}

But I don't see any comparable option for build-lib.

I believe this is a blocker for writing native extensions on Darwin.

(Darwin also differentiates between "dynamic library" and "bundle," but the functional differences between these two have greatly lessened over time, so it's unclear if the ability to compile with -bundle is actually an important use case or not.)

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

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.os-macosmacOS

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions