Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Compiling SFML Android Application  (Read 3493 times)

0 Members and 1 Guest are viewing this topic.

Sathorod

  • Newbie
  • *
  • Posts: 5
    • View Profile
Compiling SFML Android Application
« on: July 19, 2014, 05:23:03 pm »
I successfully built SFML and the example application with no problems, but I've started to make a game with it and I'm getting a bunch of linker errors. Heres the output of ndk-build.

Code: [Select]
$ ndk-build
[armeabi-v7a] Compile++ thumb: game <= main.cpp
[armeabi-v7a] Compile++ thumb: game <= Game.cpp
[armeabi-v7a] Compile++ thumb: game <= GameState.cpp
[armeabi-v7a] Compile++ thumb: game <= ResourceManager.cpp
[armeabi-v7a] Prebuilt       : libsfml-graphics.so <= <NDK>/sources/sfml/lib/armeabi-v7a/
[armeabi-v7a] Prebuilt       : libsfml-audio.so <= <NDK>/sources/sfml/lib/armeabi-v7a/
[armeabi-v7a] Prebuilt       : libsfml-network.so <= <NDK>/sources/sfml/lib/armeabi-v7a/
[armeabi-v7a] Prebuilt       : libsfml-window.so <= <NDK>/sources/sfml/lib/armeabi-v7a/
[armeabi-v7a] Prebuilt       : libsfml-system.so <= <NDK>/sources/sfml/lib/armeabi-v7a/
[armeabi-v7a] SharedLibrary  : libgame.so
/Programming/Android/NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Programming/Android/NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO ./obj/local/armeabi-v7a/libsfml-graphics.so
/Programming/Android/NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Programming/Android/NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO ./obj/local/armeabi-v7a/libsfml-audio.so
/Programming/Android/NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Programming/Android/NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO ./obj/local/armeabi-v7a/libsfml-network.so
/Programming/Android/NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Programming/Android/NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO ./obj/local/armeabi-v7a/libsfml-window.so
/Programming/Android/NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Programming/Android/NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO ./obj/local/armeabi-v7a/libsfml-system.so
jni/Game.cpp:14: error: undefined reference to 'sf::String::String(char const*, std::locale const&)'
jni/ResourceManager.cpp:69: error: undefined reference to 'sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
jni/ResourceManager.cpp:83: error: undefined reference to 'sf::Font::loadFromFile(std::string const&)'
jni/ResourceManager.cpp:108: error: undefined reference to 'sf::SoundBuffer::loadFromFile(std::string const&)'
jni/ResourceManager.cpp:137: error: undefined reference to 'sf::SoundBuffer::loadFromFile(std::string const&)'
jni/ResourceManager.cpp:153: error: undefined reference to 'sf::SoundBuffer::loadFromFile(std::string const&)'
jni/ResourceManager.cpp:170: error: undefined reference to 'sf::Music::openFromFile(std::string const&)'
jni/ResourceManager.cpp:198: error: undefined reference to 'sf::Music::openFromFile(std::string const&)'
jni/ResourceManager.cpp:213: error: undefined reference to 'sf::Music::openFromFile(std::string const&)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libgame.so] Error 1

I've never seen those "is referenced by DSO" errors so I have no clue what they mean, and the undefined references don't make sense seeing as I'm not getting those errors with other files that use functions from graphics and audio sfml modules, so why would just the resource manager not find the symbols?

My Application.mk
Code: [Select]
NDK_TOOLCHAIN_VERSION := 4.8
APP_PLATFORM := android-9
APP_STL := gnustl_static
APP_CPPFLAGS := -std=c++0x
APP_ABI := armeabi-v7a

Android.mk
Code: [Select]
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := game

LOCAL_SRC_FILES := main.cpp Game.cpp GameState.cpp ResourceManager.cpp

LOCAL_SHARED_LIBRARIES := sfml-system
LOCAL_SHARED_LIBRARIES += sfml-window
LOCAL_SHARED_LIBRARIES += sfml-graphics
LOCAL_SHARED_LIBRARIES += sfml-audio
LOCAL_SHARED_LIBRARIES += sfml-network
LOCAL_WHOLE_STATIC_LIBRARIES := sfml-main

include $(BUILD_SHARED_LIBRARY)

$(call import-module,sfml)

Could it have something to do with using c++11 in my project? I know sfml doesn't use c++11 at all yet, but I didn't think that would cause issues.

Sathorod

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Compiling SFML Android Application
« Reply #1 on: July 19, 2014, 05:34:49 pm »
Linking STL as shared fixes the DSO errors. Still getting undefined references though.

EDIT: I want to point out the sf::String undefined reference is on this line:

renderWindow = new sf::RenderWindow(sf::VideoMode::getDesktopMode(), "");
« Last Edit: July 19, 2014, 05:55:08 pm by Sathorod »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Compiling SFML Android Application
« Reply #2 on: July 20, 2014, 12:39:42 am »
An undefined reference means that you are not linking all that's required or linking objects/libraries in the wrong order.

In your case

jni/Game.cpp:14: error: undefined reference to 'sf::String::String(char const*, std::locale const&)'
This is found in sfml-system

jni/ResourceManager.cpp:69: error: undefined reference to 'sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
sfml-graphics for this one

jni/ResourceManager.cpp:83: error: undefined reference to 'sf::Font::loadFromFile(std::string const&)'
This is also in sfml-graphics

jni/ResourceManager.cpp:108: error: undefined reference to 'sf::SoundBuffer::loadFromFile(std::string const&)'
This one can be found in sfml-audio

jni/ResourceManager.cpp:170: error: undefined reference to 'sf::Music::openFromFile(std::string const&)'
And the final one is also in sfml-audio

Your "LOCAL_SHARED_LIBRARIES" list seems to indicate that you do indeed link all of those libraries, so I'm guessing that it must be the link order that's wrong.
I don't really know the Android build system, so I don't know in what order libraries on that list end up actually being passed to the linker (but I would guess it's either in the listed order or reverse order).
The rule to remember is that libraries or object files needing a symbol need to be listed before libraries/objects satisfying the dependency. So If you have 3 objects A, B and C and B needs something from both A and C and additionally C needs something from A, you'd link them in the order: B C A
I think the link order only really matters with static libraries, but I'm not 100% certain and personally just always follow the little rule above.
« Last Edit: July 20, 2014, 04:18:29 am by Jesper Juhl »

 

anything