Android NDK对`std :: ios_base :: Init :: Init()'的未定义引用

时间:2019-06-03 14:06:21

标签: c++ android-ndk cocos2d-x

我要从cocos2d-x 3.9迁移到cocos2d-x 3.17.2,并且在构建android studio项目时,在链接Wwise libAuroPannerMixer.a时出现错误。 NDK版本19.2,使用clang编译,wwise版本2017.1.3.6377。也许有人遇到同样的问题?

Application.mk

APP_STL := c++_static

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 - 
fsigned-char -Wno-extern-c-compat
APP_LDFLAGS := -latomic -stdlib=libc++ -lstdc++

APP_ABI := arm64-v8a
APP_SHORT_COMMANDS := true

ifeq ($(NDK_DEBUG),1)
  APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
  APP_OPTIM := debug
else
  APP_CPPFLAGS += -DNDEBUG
  APP_OPTIM := release
endif

build.gradle:

import org.gradle.internal.os.OperatingSystem

apply plugin: 'com.android.application'

android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()

    defaultConfig {
        applicationId "org.bio.brick.breaker"
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 55
        versionName "1.55"
        multiDexEnabled true

        externalNativeBuild {
            if (PROP_BUILD_TYPE == 'ndk-build') {
                ndkBuild {
                    targets 'BioBrickBreaker'
                    arguments 'NDK_TOOLCHAIN_VERSION=clang'
                    arguments '-j' + Runtime.runtime.availableProcessors()

                    def module_paths =     [project.file("../../cocos2d").absolutePath,
                                    project.file("../../cocos2d/cocos").absolutePath,
                                    project.file("../../cocos2d/external").absolutePath]
                    if (OperatingSystem.current().isWindows()) {
                        module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    }
                    else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }
                }
            }
            else if (PROP_BUILD_TYPE == 'cmake') {
                cmake {
                    targets 'BioBrickBreaker'
                    arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
                    cppFlags "-frtti -fexceptions -fsigned-char"
                }
            }
        }

        ndk {
            abiFilters = []
            abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
        }
    }

    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        jniLibs.srcDir "libs"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
    }

    externalNativeBuild {
        if (PROP_BUILD_TYPE == 'ndk-build') {
            ndkBuild {
                path "jni/Android.mk"
            }
        }
        else if (PROP_BUILD_TYPE == 'cmake') {
            cmake {
                path "../../CMakeLists.txt"
            }
        }
    }

    buildTypes {
        release {
            debuggable false
            jniDebuggable false
            renderscriptDebuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }

            externalNativeBuild {
                ndkBuild {
                   arguments 'NDK_DEBUG=0'
                }
            }
       }

        debug {
            debuggable true
            jniDebuggable true
            renderscriptDebuggable true
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=1'
                }
            }
        }
    }
}

buildscript {
    repositories {
        mavenCentral()
    }
}

repositories {
    maven {
        url "https://maven.google.com"
    }

    maven {
        url "http://maven.gameanalytics.com/release"
    }

    flatDir {
        dirs 'libs-aar'
    }
}

android.applicationVariants.all { variant ->
    delete "${buildDir}/intermediates/assets/${variant.dirName}"

    variant.mergeAssets.doLast {
        copy {
            from "${buildDir}/../../../Resources"
            into "${buildDir}/intermediates/assets/${variant.dirName}"
            exclude "**/*.gz"
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':libcocos2dx')
    implementation project(':downloader_library')
    implementation project(':license_library')
    implementation project(':zip_library')
}

输出日志:

D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(AuroPannerMixer.o): In function `__static_initialization_and_destruction_0':
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `LssAuroPannerEncoder::setSourceParameter(char const*, float)':
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:627: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:628: undefined reference to `std::string::compare(char const*) const'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `std::string::_Rep::_M_dispose(std::allocator<char> const&)':
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:249: undefined reference to `std::string::_Rep::_M_destroy(std::allocator<char> const&)'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `LssAuroPannerEncoder::setSourceParameter(char const*, float)':
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:632: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:636: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:640: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:644: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:648: undefined reference to `std::string::compare(char const*) const'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o):C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:652: more undefined references to `std::string::compare(char const*) const' follow
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `__static_initialization_and_destruction_0':
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(AuroPannerMixer.o): In function `__static_initialization_and_destruction_0':
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `LssAuroPannerEncoder::setSourceParameter(char const*, float)':
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:627: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:628: undefined reference to `std::string::compare(char const*) const'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `std::string::_Rep::_M_dispose(std::allocator<char> const&)':
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:240: undefined reference to `std::string::_Rep::_S_empty_rep_storage'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x\bits/basic_string.h:249: undefined reference to `std::string::_Rep::_M_destroy(std::allocator<char> const&)'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `LssAuroPannerEncoder::setSourceParameter(char const*, float)':
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:632: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:636: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:640: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:644: undefined reference to `std::string::compare(char const*) const'
C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:648: undefined reference to `std::string::compare(char const*) const'
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o):C:\jenkins\ws\wwise_v2017.1\wwise\Partners\Auro\AuroPanner\SoundEnginePlugin\Android/../../../auro-commons/audio/LSSAuroPanner/Src/LSSAuroPanner.cpp:652: more undefined references to `std::string::compare(char const*) const' follow
D:/dev/biobrickbreaker/proj.android/app/jni/../../../WwiseLib/android-21_arm64-v8a/Release/lib/libAuroPannerMixer.a(LSSAuroPanner.o): In function `__static_initialization_and_destruction_0':
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

2 个答案:

答案 0 :(得分:0)

我认为libAuroPannerMixer.a的构建不正确。在接下来的wwise版本中,没有Auro库。结果,我只是从项目中删除了该库,它对我来说没有任何声音麻烦。我在wwise论坛上创建了一个主题topic

答案 1 :(得分:0)

我至少看到了三个问题。

APP_LDFLAGS := -latomic -stdlib=libc++ -lstdc++

删除整行。第一个标志是多余的(使用ndk-build是自动的),第二个标志是错误的。

ndk-build在链接命令中的正确位置手动链接标准库,并使用-nostdlib++禁止编译器的默认行为。添加-stdlib=libc++可以解决这个问题,因此现在它被链接了两次并且在错误的位置。

-lstdc++链接了错误的库。

c:\jenkins\ws\wwise_v2017.1\wwise\sdk\source\build\android\android-21_arm64-v8a\include\c++\4.9.x/iostream:74: undefined reference to `std::ios_base::Init::Init()'

在此处特别注意std命名空间的路径和名称。 include\c++\4.9.x是gnustl标头的路径,而std是gnustl名称空间的名称。 libc ++使用不同的标头路径,名称空间为std::__ndk1(第二部分是内联名称空间,因此您无需担心编码时的实现细节,但它会在构建时中断,以保护您这些问题)。您的wwise库是使用gnustl构建的,并且您正在使用libc ++。这两个库不兼容,不能在同一应用程序中使用。

您需要使用libc ++重建wwise才能将其与libc ++一起使用。如果无法执行此操作,则需要还原到NDK r17(支持gnustl的最新版本)。请注意,这样一来,您还将失去对C ++ 14和C ++ 11的访问权限(以及重新引入此后修复的所有错误),因此,强烈建议您重建wwise而不是使用旧的NDK。