简体   繁体   中英

Compile protobuf-2.4.1 code on NDK, version (android-ndk-r8-windows.)

Hi All I am trying to compile protobuf-2.4.1 code on NDK version (android-ndk-r8-windows.)

I have set below:

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

I am getting following issues while doing NDK-build:

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

This is from NDK documentation:

C++ STL support:

The standalone toolchain also comes with a copy of the GNU libstdc++ library, which provides an implementation of the C++ Standard Template Library. To use it, you however need to link with the proper library:

Use -lstdc++ to link against the static library version. This ensures that all required C++ STL code is included into your final binary. This is ideal if you are only generating a single shared library or executable. This is the recommended way to do it.

  • Use -lgnustl_shared to link against the shared library version. This is required if you have several related shared libraries or executables that need to run in the same address space at runtime (some global variables need to be defined uniquely, which is not possible if you link the static libstdc++ against each one of your executables).

    If you use this option, you need to ensure that libgnustl_shared.so is also copied to your device for your code to load properly. The file is at:

$TOOLCHAIN/arm-linux-androideabi/lib/ for ARM toolchains

$TOOLCHAIN/i686-android-linux/lib/ for x86 ones.

$TOOLCHAIN/mipsel-linux-android/lib/ for MIPS toolchain

IMPORTANT: The GNU libstdc++ is licensed under the GPLv3 with a linking exception. See the following URL for details:

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

If you cannot comply with its requirements, ie you cannot redistribute the shared library, do not use it in your project.

The reason the shared version of GNU libstdc++ is not called libstdc++.so is because this would conflict at runtime with the system's own minimal C++ runtime, which is /system/lib/libstdc++.so. This enforces a new name for the GNU ELF library. This is not a problem for the static library.

I had the same error.

To solve it, you must have APP_STL := gnustl_static in your Application.mk file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM