1

大家好,我正在尝试在 NDK 版本(android-ndk-r8-windows)上编译 protobuf-2.4.1 代码。

我在下面设置:

PREBUILT=/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/android-ndk-r8-windows/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3

PLATFORM=/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/android-ndk-r8-windows/android-ndk-r8/platforms/android-4/arch-arm/

export CC="/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/android-ndk-r8-windows/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc"

export CFLAGS="-fPIC -DANDROID -nostdlib"

export ANDROID_ROOT="/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/android-ndk-r8-windows/android-ndk-r8"

export LDFLAGS="-Wl,-rpath-link=$ANDROID_ROOT/platforms/android-4/arch-arm/usr/lib/ -L$ANDROID_ROOT/platforms/android-4/arch-arm/usr/lib/"

export CPPFLAGS="-I$ANDROID_ROOT/platforms/android-4/arch-arm/usr/include/"

CPPFLAGS="-I$ANDROID_ROOT/platforms/android-4/arch-arm/usr/include/"
CPPFLAGS=$CPPFLAGS:"-I$ANDROID_ROOT/sources/cxx-stl/gnu-libstdc++/include/"
export CPPFLAGS

./configure --host=arm-eabi

我在进行 NDK 构建时遇到以下问题:

In file included from D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:33:
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:41:18: error: string: No such file or directory
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:37:18: error: vector: No such file or directory
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:48:2: error: #error "No suitable threading library available."
In file included from D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:33:
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:136: error: 'string' in namespace 'std' does not name a type
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:647: error: expected unqualified-id before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:647: error: expected ')' before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:647: error: 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(...)' must not have variable number of arguments
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:647: error: expected ';' before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:663: error: 'string' in namespace 'std' does not name a type
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:742: error: expected unqualified-id before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:742: error: expected ')' before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:742: error: expected initializer before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.h:757: error: expected constructor, destructor, or type conversion before '*' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In function 'void google::protobuf::internal::VerifyVersion(int, int, const char*)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:62: error: 'VersionString' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:74: error: 'VersionString' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: At global scope:
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:84: error: 'string' does not name a type
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:108: error: ISO C++ forbids declaration of 'string' with no type
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:108: error: expected ',' or '...' before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In function 'void google::protobuf::internal::DefaultLogHandler(google::protobuf::LogLevel, const char*, int, int)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:114: error: 'message' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: At global scope:
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:119: error: ISO C++ forbids declaration of 'string' with no type
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:119: error: expected ',' or '...' before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:123: error: expected initializer before '*' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:141: error: ISO C++ forbids declaration of 'string' with no type
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:141: error: expected ',' or '...' before '&' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(int)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:142: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:142: error: 'value' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(const char*)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:147: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(char)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:168: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: At global scope:
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:169: error: redefinition of 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(int)'
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:141: error: 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(int)' previously defined here
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(google::protobuf::uint)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:170: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(long int)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:171: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(long unsigned int)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:172: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(double)':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:173: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: In member function 'void google::protobuf::internal::LogMessage::Finish()':
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:190: error: 'log_handler_' is not a member of 'google::protobuf::internal'
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:190: error: 'message_' was not declared in this scope
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc: At global scope:
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:208: error: expected constructor, destructor, or type conversion before '*' token
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:377: error: expected '}' at end of input
D:/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/jni/src/google/protobuf/stubs/common.cc:377: error: expected '}' at end of input
/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/android-ndk-r8-windows/android-ndk-r8/build/core/build-binary.mk:243: recipe for target `/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/obj/local/armeabi/objs/protobuf/src/google/protobuf/stubs/common.o' failed
make: *** [/cygdrive/d/D_Drive/Project/Pr/CCore/Code/NDK/eclipse-SDK-3.7.1-win32/eclipse/workspace/CMNC/obj/local/armeabi/objs/protobuf/src/google/protobuf/stubs/common.o] Error 1
4

2 回答 2

1

这是来自 NDK 文档:

C++ STL 支持:

独立工具链还附带 GNU libstdc++ 库的副本,它提供了 C++ 标准模板库的实现。但是,要使用它,您需要链接到正确的库:

使用 -lstdc++ 链接静态库版本。这可确保所有必需的 C++ STL 代码都包含在您的最终二进制文件中。如果您只生成单个共享库或可执行文件,这是理想的选择。这是推荐的方法。

  • 使用 -lgnustl_shared 链接到共享库版本。如果您有多个相关的共享库或可执行文件需要在运行时在同一地址空间中运行,则这是必需的(一些全局变量需要唯一定义,如果您将静态 libstdc++ 链接到每个可执行文件,则这是不可能的) .

    如果您使用此选项,您需要确保 libgnustl_shared.so 也被复制到您的设备,以便您的代码正确加载。该文件位于:

$TOOLCHAIN/arm-linux-androideabi/lib/ 用于 ARM 工具链

$TOOLCHAIN/i686-android-linux/lib/ 对于 x86 的。

$TOOLCHAIN/mipsel-linux-android/lib/ 用于 MIPS 工具链

重要提示:GNU libstdc++ 在 GPLv3 下获得许可,但有一个链接例外。有关详细信息,请参阅以下 URL:

      http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01s02.html

如果你不能满足它的要求,即你不能重新分发共享库,不要在你的项目中使用它。

GNU libstdc++ 的共享版本不称为 libstdc++.so 的原因是因为这会在运行时与系统自己的最小 C++ 运行时冲突,即 /system/lib/libstdc++.so。这为 GNU ELF 库强制使用了一个新名称。这对于静态库来说不是问题。

于 2012-06-11T05:54:16.017 回答
0

我有同样的错误。

要解决它,您必须APP_STL := gnustl_staticApplication.mk文件中有。

于 2012-06-16T15:19:16.257 回答