Linker error for Godot Native in Android

Godot Version

4.3

Question

Cannot build Godot native library (so) for android on Mac OS 15.
I followed these steps: Compiling for Android — Godot Engine (stable) documentation in English

The SDK and NDK seems to be setup well. Building progresses until linking, where this issue happens:

Linking Shared Library solitaire/bin/libbachey.android.template_debug.arm64.so ...
ld: error: unknown argument '-dynamic', did you mean '-Bdynamic'
ld: error: unknown argument '-dylib'
ld: error: unknown argument '-arch'
ld: error: unknown argument '-platform_version'
ld: error: unable to find library -lto_library
ld: error: cannot open /Users/bacsigabor/Library/Android/sdk/ndk/23.2.8568313/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLTO.dylib: No such file or directory
ld: error: cannot open x86_64: No such file or directory
ld: error: cannot open macos: No such file or directory
ld: error: cannot open 15.0.0: No such file or directory
ld: error: cannot open 0.0.0: No such file or directory
ld: error: unable to find library -lc++
ld: error: unable to find library -lSystem
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [solitaire/bin/libbachey.android.template_debug.arm64.so] Error 1
scons: building terminated because of errors.
bacsigabor@Mac godot-solitaire % 

I tried the setup steps for windows, but similarly Scons fails at linking:

solitaire\bin\libbachey.android.template_debug.arm64.so ...
=====
lld: error: unable to find library -lc++
lld: error: unable to find library -lmingw32
lld: error: unable to find library -lgcc_s
lld: error: unable to find library -lgcc
lld: error: unable to find library -lmoldname
lld: error: unable to find library -lmingwex
lld: error: unable to find library -lmsvcrt
lld: error: unable to find library -ladvapi32
lld: error: unable to find library -lshell32
lld: error: unable to find library -luser32
lld: error: unable to find library -lkernel32
lld: error: unable to find library -lmingw32
lld: error: unable to find library -lgcc_s
lld: error: unable to find library -lgcc
lld: error: unable to find library -lmoldname
lld: error: unable to find library -lmingwex
lld: error: unable to find library -lmsvcrt
lld: error: unable to find library -lkernel32
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Why? What could I miss? Are there other important settings than ANDROID_HOME environment variable or do I need additional step for the SConstruct file?

ld: error: cannot open x86_64: No such file or directory

with Adding support for x86 devices ?

try without, only with arm32 and arm64


arm32 requires some older Android devices, 6y or older. I haven’t needed x86 support on Android yet.

I tried with scons command to build android .so file:

scons platform=android target=template_debug arch=arm64

That should not have x86 in it. I think the issue is something else. Maybe something is missing from the documentation I linked above for Silicon Mac (but apparently for Windows too). I was hoping I could get my native library built for Android at least on my Windows or Mac computer, but let’s focus on Mac.

These are my environment variables on my MacMini M1, set up about 1 year ago.

less ~/.zshrc

export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
export ANDROID_HOME="/Users/alex/Develop/Android/SDK"
export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/25.1.8937393"
export ANDROID_SDK_ROOT="/Users/alex/Develop/Android/SDK"
export PATH="$PATH:$ANDROID_HOME/cmdline-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmake/3.22.1/bin"

Looks fine. I noticed though you are using a newer version of NDK. I used the exact same what the documentation states.

export PATH="$HOME/.local/bin:$PATH"
export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
export ANDROID_HOME="/Users/bacsigabor/Library/Android/sdk"
export ANDROID_SDK_ROOT="/Users/bacsigabor/Library/Android/sdk"
export ANDROID_NDK_ROOT="/Users/bacsigabor/Library/Android/sdk/ndk/23.2.8568313"
export ANDROID_NDK_HOME="/Users/bacsigabor/Library/Android/sdk/ndk/23.2.8568313"
export PATH="$PATH:$ANDROID_HOME/cmdline-tools:$ANDROID_HOME/cmdline-tools/late$




How about your SConstruct file? Does it have anything for Android?
Mine is just:

#!/usr/bin/env python
import os
import sys

env = SConscript("godot-cpp/SConstruct")

# For reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")

AddOption(
    '--opt',
    action='store_true',
    help='optimise',
    default=False)

if GetOption('opt'):
    env.Append(CXXFLAGS=['-O3']) 
    env['LINKFLAGS'] = []
else:
    env.Append(CXXFLAGS=['-g', '-O0'])
    env['LINKFLAGS'] = ['-g']

if env["platform"] == "macos":
    library = env.SharedLibrary(
        "solitaire/bin/libbachey.{}.{}.framework/libbachey.{}.{}".format(
            env["platform"], env["target"], env["platform"], env["target"]
        ),
        source=sources,
    )
else:
    library = env.SharedLibrary(
        "solitaire/bin/libbachey{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
        source=sources,
    )

Default(library)

Got the solution,

This should not be for Android builds. Now the library builds well.

1 Like

yes, but scons somehow still uses an older version

[ 96%] Compiling core/error/error_macros.cpp ...
[ 99%] Copy("platform/android/java/lib/libs/debug/arm64-v8a/libc++_shared.so", 
"/Users/alex/Develop/Android/SDK/ndk/23.2.8568313/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so")
[100%] Linking Static Library core/libcore.android.template_debug.arm64.a ...
1 Like