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.
|
} else if (mem.eql(u8, arg, "--allow-shlib-undefined") or |
|
mem.eql(u8, arg, "-allow-shlib-undefined")) |
|
{ |
|
linker_allow_shlib_undefined = true; |
|
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.)
To build a native Python extension on Darwin, the option
-undefined dynamic_lookupmust 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:
For
zig ccit appears there is an option--allow-shlib-undefinedthat will achieve the desired effect.zig/src/main.zig
Lines 1260 to 1263 in 9270aae
zig/src/link/MachO.zig
Lines 781 to 784 in 9270aae
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
-bundleis actually an important use case or not.)