You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
macOS builds expose stack_size option in LINKEDFOORSHARED and pyconfig #79141
Sorry, I can't reproduce that behavior. What's more, that LINKFORSHARED value does not appear to be correct. Have you tried doing a build from a clean build dicectory while rerunning ./configure? What does your ./configure look like and do have any relevant env variables set?
Oh, you didn't mention --enable-shared! But still it's not clear to me what problem your last results shows. The value of python3-config --ldflags looks fine (ignore the repeated -framework CoreFoundation). Are you still getting the "ld: -stack_size option can ...' message when you built the second time? An installed --enable-shared build for me works just fine when using a non-standard prefix, i.e. a location where there is not already a Python3 installed. So I still can't reproduce a problem.
By the way, I always recommend to avoid using the --enable-shared option for macOS builds; I know there are cases in the past where there *has* been build issues when building shared and there is already a Python installed at that prefix. If possible, stick either a "plain Unix" build (no --enable-shared, no --enable-framework) or a framework build. You're less likely to run into at first glance head-scratching building and linking issues.
xzcvczx commented on Oct 11, 2018
xzcvczxmannequin
MannequinAuthor
More actions
ah ok, sorry i wasn't clear at first, the issue isn't when building python its when building a library which depends on python in this case libxml2, which when given the --enable-python stuff uses "PYTHON_LIBS=python$PYTHON_VERSION-config --ldflags" and therefore is being given the -Wl,stack_size linker option which is not valid for non main executables according to the error produced from clang
OK, now I finally get it, thanks, my fault. Yes, we probably shouldn't be passing stack_size through to applications trying to embed Python in LINkFORSHARED and pyconfig. That's an area that we don't test very well nor have tests for, AFAIK. Would it possible for you to provide a simple example of building libxml2 that would allow us to more easily test this?
changed the title [-]python-config bad ldflags on macOS[/-][+]macOS builds expose stack_size option in LINKEDFOORSHARED and pyconfig[/+]on Oct 11, 2018
xzcvczx commented on Oct 11, 2018
xzcvczxmannequin
MannequinAuthor
More actions
oh the rabbit hole...
as i have other builds of python3.7 on my system i wanted to ensure it used the correct python and python-config (python 3.7 was built and installed into $HOME/Projects/python/inst/) as such its a rather convoluted configure command for libxml2
the LDFLAGS envvar was required as python-config --ldflags also does not provide -L for the python libary
$make
ld: library not found for -lpython3.7m
in config.log for libxml2 (PYTHON_LIBS which is the output of $HOME/Projects/python/python3-config --ldflags)
PYTHON_LIBS='-lpython3.7m -ldl -framework CoreFoundation -Wl,-stack_size,1000000 -framework CoreFoundation'
after LDFLAGS="..." is added
$make
...
CCLD libxml2mod.la
ld: -stack_size option can only be used when linking a main executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
if you want more log lines please let me know but those should be the only relevant ones
Activity
xzcvczx commentedon Oct 11, 2018
if you didn't build python as a framework it adds sysconfig.get_config_vars('LINKFORSHARED') when you run 'python-config --ldflags' this resolves to
>>> sysconfig.get_config_var('LINKFORSHARED') '-Wl,-stack_size,1000000 -framework CoreFoundation /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python'the '-Wl,-stack_size' ldflag causes issues for clang with the error
"ld: -stack_size option can only be used when linking a main executable"
ned-deily commentedon Oct 11, 2018
Sorry, I can't reproduce that behavior. What's more, that LINKFORSHARED value does not appear to be correct. Have you tried doing a build from a clean build dicectory while rerunning ./configure? What does your ./configure look like and do have any relevant env variables set?
>>> sysconfig.get_config_var('LINKFORSHARED') '-Wl,-stack_size,1000000 -framework CoreFoundation'xzcvczx commentedon Oct 11, 2018
with a fresh 3.7.0 download
./configure --prefix=... --enable-shared
make -j5
make install
path/to/python3-config --ldflags
-lpython3.7m -ldl -framework CoreFoundation -Wl,-stack_size,1000000 -framework CoreFoundation
ned-deily commentedon Oct 11, 2018
Oh, you didn't mention --enable-shared! But still it's not clear to me what problem your last results shows. The value of python3-config --ldflags looks fine (ignore the repeated -framework CoreFoundation). Are you still getting the "ld: -stack_size option can ...' message when you built the second time? An installed --enable-shared build for me works just fine when using a non-standard prefix, i.e. a location where there is not already a Python3 installed. So I still can't reproduce a problem.
By the way, I always recommend to avoid using the --enable-shared option for macOS builds; I know there are cases in the past where there *has* been build issues when building shared and there is already a Python installed at that prefix. If possible, stick either a "plain Unix" build (no --enable-shared, no --enable-framework) or a framework build. You're less likely to run into at first glance head-scratching building and linking issues.
xzcvczx commentedon Oct 11, 2018
ah ok, sorry i wasn't clear at first, the issue isn't when building python its when building a library which depends on python in this case libxml2, which when given the --enable-python stuff uses "PYTHON_LIBS=
python$PYTHON_VERSION-config --ldflags" and therefore is being given the -Wl,stack_size linker option which is not valid for non main executables according to the error produced from clangned-deily commentedon Oct 11, 2018
OK, now I finally get it, thanks, my fault. Yes, we probably shouldn't be passing stack_size through to applications trying to embed Python in LINkFORSHARED and pyconfig. That's an area that we don't test very well nor have tests for, AFAIK. Would it possible for you to provide a simple example of building libxml2 that would allow us to more easily test this?
https://docs.python.org/3/extending/embedding.html#compiling-and-linking-under-unix-like-systems
[-]python-config bad ldflags on macOS[/-][+]macOS builds expose stack_size option in LINKEDFOORSHARED and pyconfig[/+]xzcvczx commentedon Oct 11, 2018
oh the rabbit hole...
as i have other builds of python3.7 on my system i wanted to ensure it used the correct python and python-config (python 3.7 was built and installed into $HOME/Projects/python/inst/) as such its a rather convoluted configure command for libxml2
LDFLAGS="-L$HOME/Projects/python/inst/lib" PATH=/Users/simon/Projects/python/inst/bin/:$PATH ./configure --prefix=/Users/simon/Projects/python/inst/ --with-python=/Users/simon/Projects/python/inst/bin/python3 --with-python-install-dir=/Users/simon/Projects/python/inst/lib/python3.7/site-packages
the LDFLAGS envvar was required as python-config --ldflags also does not provide -L for the python libary
$make
ld: library not found for -lpython3.7m
in config.log for libxml2 (PYTHON_LIBS which is the output of $HOME/Projects/python/python3-config --ldflags)
PYTHON_LIBS='-lpython3.7m -ldl -framework CoreFoundation -Wl,-stack_size,1000000 -framework CoreFoundation'
after LDFLAGS="..." is added
$make
...
CCLD libxml2mod.la
ld: -stack_size option can only be used when linking a main executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
if you want more log lines please let me know but those should be the only relevant ones
ronaldoussoren commentedon Dec 7, 2023
This issue appears to be out of date:
python3.x-config --ldflagsandpython3.x-config --ldflags --embedno longer include-stack_size.The
LINKFORSHAREDconfigvar does include that option, but that's correct as the variable is meant to be used for linking the python executable.I intent to close this issue.