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

[build][CMake] Unable to build raylib as a shared library for Android #4484

Open
3 tasks done
OussamaTeyib opened this issue Nov 12, 2024 · 1 comment
Open
3 tasks done
Labels
help needed - please! I need help with this issue platform: Android Android platform

Comments

@OussamaTeyib
Copy link
Contributor

  • I tested it on the latest Raylib version from the master branch
  • I checked there is no similar issue already reported (in the Android section)
  • I checked the documentation on the wiki

Issue description
I encountered a linker error when building Raylib as a shared library for Android using the provided CMake configuration.The error indicates an "undefined symbol: main" when trying to link the Raylib shared library.


Since Android requires native applications to have an android_main() entry, Raylib's implementation allows the user to define a main() function, which is then called by Raylib. This must be taken into account by the build system.

Steps to reproduce

  1. Use the provided Raylib CMake build system for Android (configured with the Android NDK).

  2. Run the following CMake command to configure the build:

    cmake -B Build -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%\build\cmake\android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-35 -DPLATFORM=Android -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -G Ninja
    
  3. Build the shared library:

    cmake --build build
    
  4. Encounter the linker error during the linking step:

    ld.lld: error: undefined symbol: main
    >>> referenced by rcore_android.c:279 (C:/coding/raylib/raylib/src/platforms/rcore_android.c:279)
    >>>               raylib/CMakeFiles/raylib.dir/rcore.c.o:(android_main)
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

Additional information

  • This issue does not occur when using the provided Makefile, which works as expected.
  • The problem seems to be related to the CMake configuration.
  • The issue does not occur when building a static library.

Environment

  • Raylib version: Latest master branch
  • Operating System: Windows 10
  • Android NDK version: r27b
  • CMake version: 3.10.4
@raysan5 raysan5 changed the title [build] Unable to build raylib as a shared library for Android [build][CMake] Unable to build raylib as a shared library for Android Nov 14, 2024
@raysan5
Copy link
Owner

raysan5 commented Nov 24, 2024

Just note that I do not maintain the CMake build system...

@raysan5 raysan5 added the platform: Android Android platform label Nov 24, 2024
@raysan5 raysan5 added the help needed - please! I need help with this issue label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help needed - please! I need help with this issue platform: Android Android platform
Projects
None yet
Development

No branches or pull requests

2 participants