Задать вопрос

Ошибки undefined reference при попытке портирования с++ игры на андроид?

Пытался портировать свою игру, написанную на с++ на андроид. Но мешают этому ошибки undefined reference при компиляции.
Вывод компилятора:

> Task :app:externalNativeBuildDebug
Build SDL2 x86_64
Android NDK: WARNING: Unsupported source file extensions in /home/nikita/Android/podval/app/jni/SDL2_mixer/external/mpg123-1.25.6/Android.mk for module mpg123    
Android NDK:   src/libmpg123/icy.h src/libmpg123/icy2utf8.h src/libmpg123/synth.h src/libmpg123/synth_8bit.h src/libmpg123/dither.h    
make: '/home/nikita/Android/podval/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/libSDL2.so' is up to date.
Build SDL2_image x86_64
Android NDK: WARNING: Unsupported source file extensions in /home/nikita/Android/podval/app/jni/SDL2_mixer/external/mpg123-1.25.6/Android.mk for module mpg123    
Android NDK:   src/libmpg123/icy.h src/libmpg123/icy2utf8.h src/libmpg123/synth.h src/libmpg123/synth_8bit.h src/libmpg123/dither.h    
make: '/home/nikita/Android/podval/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/libSDL2_image.so' is up to date.
Build hidapi x86_64
Android NDK: WARNING: Unsupported source file extensions in /home/nikita/Android/podval/app/jni/SDL2_mixer/external/mpg123-1.25.6/Android.mk for module mpg123    
Android NDK:   src/libmpg123/icy.h src/libmpg123/icy2utf8.h src/libmpg123/synth.h src/libmpg123/synth_8bit.h src/libmpg123/dither.h    
make: '/home/nikita/Android/podval/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/libhidapi.so' is up to date.
Build main x86_64
Android NDK: WARNING: Unsupported source file extensions in /home/nikita/Android/podval/app/jni/SDL2_mixer/external/mpg123-1.25.6/Android.mk for module mpg123    
Android NDK:   src/libmpg123/icy.h src/libmpg123/icy2utf8.h src/libmpg123/synth.h src/libmpg123/synth_8bit.h src/libmpg123/dither.h    
[x86_64] SharedLibrary  : libmain.so
jni/src/sdl.cpp:127: error: undefined reference to 'std::__ndk1::to_string(int)'
jni/src/sdl.cpp:146: error: undefined reference to 'std::__ndk1::to_string(int)'
jni/src/clases/small_clases.cpp:91: error: undefined reference to 'std::__ndk1::to_string(int)'
jni/src/logic.cpp:254: error: undefined reference to 'std::__ndk1::to_string(int)'
jni/src/game.cpp:189: error: undefined reference to 'std::__ndk1::to_string(unsigned int)'
jni/src/game.cpp:189: error: undefined reference to 'std::__ndk1::to_string(unsigned int)'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:466: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:466: error: undefined reference to 'std::__ndk1::locale::~locale()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:383: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:383: error: undefined reference to 'std::__ndk1::locale::~locale()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/istream:1469: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/istream:1469: error: undefined reference to 'std::__ndk1::locale::~locale()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/streambuf:307: error: undefined reference to 'std::__ndk1::locale::~locale()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:249: error: undefined reference to 'std::__ndk1::codecvt<char, char, mbstate_t>::id'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:250: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ios:344: error: undefined reference to 'vtable for std::__ndk1::ios_base'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ios:704: error: undefined reference to 'std::__ndk1::ios_base::~ios_base()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ios:711: error: undefined reference to 'std::__ndk1::ios_base::init(void*)'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/streambuf:232: error: undefined reference to 'std::__ndk1::locale::locale()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:241: error: undefined reference to 'std::__ndk1::codecvt<char, char, mbstate_t>::id'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:242: error: undefined reference to 'std::__ndk1::locale::has_facet(std::__ndk1::locale::id&) const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/streambuf:149: error: undefined reference to 'std::__ndk1::locale::locale(std::__ndk1::locale const&)'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ios:547: error: undefined reference to 'std::__ndk1::ios_base::clear(unsigned int)'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ios:777: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:249: error: undefined reference to 'std::__ndk1::ctype<char>::id'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:250: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:249: error: undefined reference to 'std::__ndk1::num_get<char, std::__ndk1::istreambuf_iterator<char, std::__ndk1::char_traits<char> > >::id'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:250: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:279: error: undefined reference to 'std::uncaught_exception()'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:249: error: undefined reference to 'std::__ndk1::num_put<char, std::__ndk1::ostreambuf_iterator<char, std::__ndk1::char_traits<char> > >::id'
/usr/src/NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__locale:250: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/usr/src/NDK/build/core/build-binary.mk:725: /home/nikita/Android/podval/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/libmain.so] Error 1

> Task :app:externalNativeBuildDebug FAILED

FAILURE: Build failed with an exception.


build.gradle

def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY');
def buildAsApplication = !buildAsLibrary
if (buildAsApplication) {
    apply plugin: 'com.android.application'
}
else {
    apply plugin: 'com.android.library'
}

android {
    compileSdkVersion 26
    defaultConfig {
        if (buildAsApplication) {
            applicationId "org.libsdl.showimage"
        }
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            ndkBuild {
                arguments "APP_PLATFORM=android-16"
                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            }
             cmake {
                arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
                //abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
                abiFilters 'arm64-v8a'
                cppFlags "-DANDROID_STL=c++_shared"
             }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
        sourceSets.main {
            jniLibs.srcDir 'libs'
        }
        externalNativeBuild {
            ndkBuild {
                path 'jni/Android.mk'
            }
             //cmake {
             //    path 'jni/CMakeLists.txt'
             //}
        }
       
    }
    lintOptions {
        abortOnError false
    }
    
    if (buildAsLibrary) {
        libraryVariants.all { variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith(".aar")) {
                    def fileName = "org.libsdl.showimage.aar";
                    output.outputFile = new File(outputFile.parent, fileName);
                }
            }
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
}


Что я делаю не так?
  • Вопрос задан
  • 199 просмотров
Подписаться 1 Средний Комментировать
Решения вопроса 1
@Nikita_yfh Автор вопроса
в CMakeLists.txt добавил строку APP_STL := c++_shared и все скомпилировалось
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 2
alekseyHunter
@alekseyHunter
Android developer
Закинь лог ошибок в переводчик и посмотри что не так.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы