Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kiwisolver error ld: error: undefined symbol: main #3122

Closed
shivaraj-arch opened this issue Mar 7, 2025 · 12 comments · May be fixed by #3124
Closed

kiwisolver error ld: error: undefined symbol: main #3122

shivaraj-arch opened this issue Mar 7, 2025 · 12 comments · May be fixed by #3124
Labels

Comments

@shivaraj-arch
Copy link

shivaraj-arch commented Mar 7, 2025

OS : mac
command: buildozer -v android debug
buildozer.spec : p4a.branch = develop

Can someone point why is this ld error caused while building 'kiwisolver._cext' extension

kiwisolver.error.txt

[DEBUG]: /Users/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -target aarch64-linux-android24 -fomit-frame-pointer -march=armv8-a -fPIC -target aarch64-linux-android24 -fomit-frame-pointer -march=armv8-a -fPIC -I/Users/workspace/stocks/android/matplotlibapp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/arm64-v8a__ndk_target_24/python3/Include -bundle -undefined dynamic_lookup -L/Users/workspace/stocks/android/matplotlibapp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/libs_collections/matplotlibapp/arm64-v8a -L/Users/workspace/stocks/android/matplotlibapp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/arm64-v8a__ndk_target_24/python3/android-build -lpython3.11 -target aarch64-linux-android24 -fomit-frame-pointer -march=armv8-a -fPIC -I/Users/workspace/stocks/android/matplotlibapp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/arm64-v8a__ndk_target_24/python3/Include build/temp.macosx-15.3-arm64-cpython-311/py/src/constraint.o build/temp.macosx-15.3-arm64-cpython-311/py/src/expression.o build/temp.macosx-15.3-arm64-cpython-311/py/src/kiwisolver.o build/temp.macosx-15.3-arm64-cpython-311/py/src/solver.o build/temp.macosx-15.3-arm64-cpython-311/py/src/strength.o build/temp.macosx-15.3-arm64-cpython-311/py/src/term.o build/temp.macosx-15.3-arm64-cpython-311/py/src/variable.o -o build/lib.macosx-15.3-arm64-cpython-311/kiwisolver/_cext.cpython-311-darwin.so -stdlib=libc++

[DEBUG]: clang-14: warning: argument unused during compilation: '-bundle' [-Wunused-command-line-argument]
[DEBUG]: clang-14: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
[DEBUG]: ld: error: undefined symbol: main
[DEBUG]: >>> referenced by crtbegin.c

@AndreMiras AndreMiras transferred this issue from kivy/buildozer Mar 7, 2025
@AndreMiras
Copy link
Member

Did you get this working in the past or is it the first time you're trying?
I'm asking because we made a recent kiwisolver recipe update.
You can verify if this is a regression from #3118 by pointing p4a.commit to the commit before the merge. Start from clean build.
If it's a recent regression then the fix is simple.

@T-Dynamos
Copy link
Contributor

That's same error macos runner is having in github right now.

@shivaraj-arch
Copy link
Author

shivaraj-arch commented Mar 7, 2025

Did you get this working in the past or is it the first time you're trying? I'm asking because we made a recent kiwisolver recipe update. You can verify if this is a regression from #3118 by pointing p4a.commit to the commit before the merge. Start from clean build. If it's a recent regression then the fix is simple.

if __init__.py is replaced, old error resurfaces - Python.h not found.
tried setting env flags but seems its not finding it. should we set them in another file?

@RobertFlatt
Copy link
Contributor

RobertFlatt commented Mar 11, 2025

@T-Dynamos

I think the recipe should have += not = here:

        env["CFLAGS"] = flags
        env["CPPFLAGS"] = flags

Because the log error is due to trying to create an executable, so some compiler flags are wrong. And other recipes use += in this case.

RobertFlatt added a commit to RobertFlatt/python-for-android that referenced this issue Mar 12, 2025
Bump version,  change depends to hostpython_prerequisites.
Fix kivy#3122
@RobertFlatt
Copy link
Contributor

I tried adding the above fix to a very loosely related PR #3124
It did not fix the issue.

@RobertFlatt
Copy link
Contributor

RobertFlatt commented Mar 14, 2025

I note the following warnings

clang-14: warning: argument unused during compilation: '-bundle' [-Wunused-command-line-argument]
clang-14: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]

These two options tell Clang to link as a .so , Clang is not seeing them and we get an executable.
These flags only occur in the link step.

The general form of the link on MacOS is (the extra_include_file is from CPPFLAGS, and CFLAGS is not used) .

Clang -lots_of_options -Iextra_include_file  -bundle -undefined dynamic_lookup  -Lsome_lib -Iextra_include_file many_files.o target.so

Linux replaces -bundle -undefined dynamic_lookup (from the warnings above) with -shared.

It looks like MacOS is picky about argument order. I suggest this will not be specific to this recipe. And will occur when CPPFLAGS is set in a recipe.

The resolution is probably not to supply compile options to a link step. (And definitely not twice!).

As far as I can see PyProjectRecipe would have to make the distinction between setuptools extra_compile_args, and extra_link_args. Its child MesonRecipe does make this distinction.

For the case of args supplied from a recipe, I think these should/could not be specified from a .toml file, so this is a PyProjectRecipe use of setuptools issue.

@T-Dynamos
@AndreMiras

@AndreMiras
Copy link
Member

Thank you for your input @RobertFlatt , yes that sounds reasonable, that could be it.
This can probably be confirmed by updating the kiwisolver recipe and sanitizing the linker flags.
I don't have access to macOS 13 or 14 to try sadly (I've tried playing with sickcodes/Docker-OSX, but no luck so far) and debugging using the CI only is a bit impractical.
Feel free to give it a try if you have a chance to. Ideally I wouldn't refactor the base recipe classes, but try to fix at kiwisolver level first to confirm it with a low regression risk

@RobertFlatt
Copy link
Contributor

RobertFlatt commented Mar 21, 2025

@AndreMiras
Testing my opinions written above sounds like a really good idea! I don't have Mac access either.

I did dig around in recipy.py, couldn't find anything lower level than PyProjectRecipy's call to setuptools. Which makes some sense. But I couldn't find the default usage of CPPFLAGS either , so I know that I don't know how those pieces fit together. I'd be a fool to try to mess with that. But PyProjectRecipy looks like the place that configures setuptools build.

Don't really need a Mac initially, it is sufficient to look at the compile argument order on an Android build (assuming the reasoning in the previous post). The Android Clang, of course does not complain.

Since PyProjectRecipe is new and only in the p4a develop version (and undocumented), I suggest the developer owns this one.

@AndreMiras
Copy link
Member

So I got a macOS 13 (Ventura) setup working using dockur/macos to try to reproduce, but I can successfully build kiwisolver with it 🤷‍♂
Steps to reproduce:

export PYTHONFORANDROID_PREREQUISITES_INSTALL_INTERACTIVE=0
export ANDROID_HOME=${HOME}/.android
export ANDROID_SDK_ROOT=${HOME}/.android/android-sdk
export ANDROID_SDK_HOME=${HOME}/.android/android-sdk
export ANDROID_NDK_HOME=${HOME}/.android/android-ndk

git clone https://github.com/kivy/python-for-android.git
cd python-for-android
python3.9 -m venv venv
. venv/bin/activate
pip install -e .
python pythonforandroid/prerequisites.py
cd testapps/on_device_unit_tests/
python setup.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --arch=x86_64 --requirements kivy,python3

It's weird that I'm trying to run it just like in the CI and it works for me 🤯
I'll keep investigating when I get a chance.
Truncated log end for reference:

[INFO]:    # Your distribution was created successfully, exiting.
[INFO]:    Dist can be found at (for now) /Users/macos/.python-for-android/dists/bdist_unit_tests_app
[INFO]:    Of the existing distributions, the following meet the given requirements:
[INFO]:         bdist_unit_tests_app: min API 24, includes recipes (hostpython3, libffi, openssl, sdl2_image, sdl2_mixer, sdl2_ttf, sqlite3, python3, sdl2, kiwisolver, setuptools, six, pyjnius, android, kivy, chardet, idna, requests, certifi, filetype, cppy, urllib3), built for archs (arm64-v8a)
[INFO]:    bdist_unit_tests_app has compatible recipes, using this one
[INFO]:    -> directory context /Users/macos/.python-for-android/build/bootstrap_builds/sdl2
[INFO]:    <- directory context /Users/macos/workspace/python-for-android/testapps/on_device_unit_tests
[INFO]:    -> directory context /Users/macos/.python-for-android/dists/bdist_unit_tests_app
No setup.py/pyproject.toml used, copying full private data into .apk.
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/tools.py'...
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/constants.py'...
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/app_service.py'...
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/app_flask.py'...
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/widgets.py'...
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/app_kivy.py'...
Compiling '/Users/macos/workspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/main.py'...      <-------------> 0% WAITING
Compiling '/Users/ma> IDLErkspace/python-for-android/testapps/on_device_unit_tests/build/bdist.android-arm64-v8a/test_app/tests/mixin.py'..> IDLE====----> 75% EXECUTING [2s]
[INFO]:    <- directory context /Users/macos/workspace/python-for-android/testapps/on_device_unit_tests                [INFO]:    Of the existing distributions, the following meet the given requirements:
[INFO]:    workibdist_unit_tests_app: min API 24, includes recipes (hostpython3, libffi, openssl, sdl2_image, sdl2_mixer, sdl2_ttf, sqlite3, python3, sdl2, kiwisolver, setuptools, six, pyjnius, android, kivy, chardet, idna, requests, certifi, filetype, cppy, urllib3), built for archs (arm64-v8a)                                                        
[INFO]:    bdist_unit_tests_app has compatible recipes, using this one
[INFO]:    # Copying android package to current directoryore) e 33.0.1
[INFO]:    # Android package filename not found in build output. Guessing...
[INFO]:    # Found android package file: /Users/macos/.python-for-android/dists/bdist_unit_tests_app/build/outputs/apk/debug/bdist_unit_tests_app-debug.apk
[INFO]:    # Add version number to android package
[INFO]:    # Android package renamed to bdist_unit_tests_app-debug-1.1.apk
[INFO]:    -> running cp /Users/macos/.python-for-android/dists/bdist_unit_tests_app/build/...(and 83 more)

AndreMiras added a commit that referenced this issue Mar 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@AndreMiras
Copy link
Member

Fixed via #3128, I'll let the PR open until tomorrow and merge it if we don't get blocking comments.
I kept it isolated instead of touching PyProjectRecipe to limit potential regressions.
If we can confirm the same bug on macOS for another PyProjectRecipe then we can try to generalise it

@RobertFlatt
Copy link
Contributor

If we can confirm the same bug on macOS for another PyProjectRecipe then we can try to generalise it

The condition I think will be PyProjectRecipe containing CPPFLAGS.

AndreMiras added a commit that referenced this issue Mar 23, 2025
🐛 Fix the kiwisolver build on macOS, fixes #3122
@shivaraj-arch
Copy link
Author

Thanks all for the fix.
env["LDFLAGS"] += " -shared"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants