how to include libprotobuf.a in cocos2d-x - android

I need to use google's protobuf in my cocos2d-x android project. I include headers and C++ files in project. But when I try to compile project via NDK, compiler return me errors:
jni/../../Classes/PromowallLibrary/protocol.pb.cpp:55: error: undefined reference to 'google::protobuf::DescriptorPool::generated_pool()'
jni/../../Classes/PromowallLibrary/protocol.pb.cpp:55: error: undefined reference to 'google::protobuf::DescriptorPool::FindFileByName(std::basic_string, std::allocator > const&) const'
jni/../../Classes/PromowallLibrary/protocol.pb.cpp:56: error: undefined reference to 'google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)'
and so on. How can I point to -lprotobuf library? I tried:
LOCAL_LDLIBS := -lprotobuf \ but that is doesn't work
UPDATE:
now I try to do in such way - I create static module:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := libprotobuf.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_CPP_EXTENSION := .cpp \
.cc
LOCAL_SRC_FILES := helloworld/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/PromowallLibrary/protocol.pb.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := libprotobuf
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)
Now I get such kind of errors:
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(common.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(generated_message_util.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(message_lite.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(repeated_field.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(wire_format_lite.o): incompatible target

Related

C++ library with Tensorflow on Android

I'm trying to build a native C++ library for the Android app. This lib uses Tensorflow C++ API (version 1.9.0 and 1.10.0) and OpenCV(3.3.0) inside. For generating wrapper I'm using Swig. I'm using Android NDK to build *.so files (I've tried with different versions of the NDK versions 10, 14, 15, 17).
I've built *.a (libtensorflow-core.a, nsync.a, libprotobuf.a)files from sources.
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
}
I have the next files:
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libnsync
LOCAL_SRC_FILES := $(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/downloads/nsync/builds/armeabi-v7a.android.c++11/nsync.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := $(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotobuf.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libtensorflow
LOCAL_SRC_FILES := $(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a
LOCAL_EXPORT_C_INCLUDES := \
$(PATH_TO_TENSORFLOW) \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/host_obj \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/downloads/eigen \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/include \
$(PATH_TO_TENSORFLOW)/tensorflow/core/public \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/downloads/nsync/public
LOCAL_STATIC_LIBRARIES += libprotobuf libnsync
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_ARM_NEON := true
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk
LOCAL_MODULE := libOcr
LOCAL_SRC_FILES := ocr/Ocr_wrap.cxx
LOCAL_LDLIBS += -landroid -llog -ldl
LOCAL_CPPFLAGS += -std=c++11
LOCAL_STATIC_LIBRARIES += libprotobuf libtensorflow
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_shared
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-21 #updated from 19 to 21
APP_OPTIM := release
LOCAL_ARM_NEON := true
During the build, I've faced a lot of errors, and the last one is:
[armeabi-v7a] SharedLibrary : libOcr.so
[armeabi-v7a] Install : liblept.so => libs/armeabi-v7a/liblept.so
[armeabi-v7a] Install : libtess.so => libs/armeabi-v7a/libtess.so
[armeabi-v7a] Install : libgnustl_shared.so => libs/armeabi-v7a/libgnustl_shared.so
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(str_util.o):str_util.cc:function tensorflow::str_util::CUnescape(tensorflow::StringPiece, std::string*, std::string*): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(log_memory.o):log_memory.cc:function tensorflow::LogMemory::RecordStep(long long, std::string const&): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(log_memory.o):log_memory.cc:function tensorflow::LogMemory::RecordTensorAllocation(std::string const&, long long, tensorflow::Tensor const&): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(log_memory.o):log_memory.cc:function tensorflow::LogMemory::RecordTensorDeallocation(long long, std::string const&): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
collect2: error: ld returned 1 exit status
make: *** [/Users/app/app/src/main/obj/local/armeabi-v7a/libOcr.so] Error 1
make: Leaving directory `/Users/app/app/src/main/jni'
:sdk:buildNative FAILED
FAILURE: Build failed with an exception.
For building *.so files I use next task in build.gradle file:
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_LOG=1'
Dear community, please help me to figure out these issues. Thank you.
Updated: APP_PLATFORM changed to android-21, better results but still have errors
I had this problem before, it's the poop library

AddressSanitizier: error: undefined reference to "__asan_report_load4"

When I compiled a test Android program by enabling the AddressSanitizier, I got this error:
error: undefined reference to __asan_report_load4
Does anyone know what happened here?
This is my Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := asan_boom.c
LOCAL_SHARED_LIBRARIES := libc
LOCAL_CFLAGS := -O1 -g -fsanitize=address -fno-omit-frame-pointer
LOCAL_MODULE := asan_boom
include $(BUILD_EXECUTABLE)

undefined reference error while building FFMPEG with NDK

I get this error while running build-ndk for my ffmpeg android project
make: *** [obj/local/armeabi-v7a/libffmpeg-test-jni.so]
undefined reference to 'av_close_input_file'
undefined reference to 'av_find_stream_info'
undefined reference to 'av_open_input_file'
undefined reference to 'avcodec_open'
Any solutions to get rid of this error ? I am very new to ffmpeg and Android NDK
This is my Android MK file
LOCAL_PATH := $(call my-dir)
#declare the prebuilt library
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg-prebuilt
LOCAL_SRC_FILES := ffmpeg-2.5.4/android/armv7-a/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := ffmpeg-2.5.4/android/armv7-a/include
LOCAL_EXPORT_LDLIBS := ffmpeg-2.5.4/android/armv7-a/libffmpeg.so
LOCAL_LDLIBS += -llog -lavutil -lavformat -lavcodec -lz -lavutil -lm
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)
#the andzop library
include $(CLEAR_VARS)
LOCAL_ALLOW_UNDEFINED_SYMBOLS=false
LOCAL_MODULE := ffmpeg-test-jni
LOCAL_SRC_FILES := ffmpeg-test-jni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-2.5.4/android/armv7-a/include
LOCAL_SHARED_LIBRARY := ffmpeg-prebuilt
LOCAL_LDLIBS := -llog -ljnigraphics -lz -lm $(LOCAL_PATH)/ffmpeg-2.5.4/android/armv7-a/libffmpeg.so
include $(BUILD_SHARED_LIBRARY)
Any Pointers much appreciated
Thanks!

Include Protobuf Library - cocos2dx

Hi I would like to add protobufs to my project. So far I am only trying with android and have not been lucky so far.
I have placed my libs : libprotobuf.a , libprotobuf-lite.a, libprotoc.a in "Protobuf" folder right where "Classes" folder can be found.
I have generated one Proto named "Msg.pb.cc" and placed it in Classes folder.
I have placed the Protobuf .h files in the classes folder. i.e. Classes/google/protobuf/....
This is what my Android.mk looks right now.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotoc
LOCAL_SRC_FILES := ../../Protobuf/libprotoc.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf-lite
LOCAL_SRC_FILES := ../../Protobuf/libprotobuf-lite.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf.a
LOCAL_SRC_FILES := ../../Protobuf/libprotobuf.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_CPP_EXTENSION := .cxx .cpp .cc
LOCAL_SRC_FILES += hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/GameSprite.cpp \
../../Classes/GameLayer.cpp \
../../Classes/Control.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/NativeInterface.cpp \
../../Classes/Msg.pb.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)
I get a lot of errors as soon as it compiles the Msg.pb.cc. Here's a few:
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
Somehow, I guess the files are not linked. The code is unable to find the protobuf library.
I don't know how Android.mk files are written and do not have much experience with cpp as well. This is just the result of some google searches and reading the original Android.mk file.
Any help is appreciated.
-cocos2dx-2.2.5
-eclipse+ADT.
-sdk 5.0.1
-ndk r8e

Undefined references appears when including iostream

I have tried to compile very simple code for android:
#include <iostream>
void foo()
{
}
But I get some linking errors:
/home/l/android-ndk-r7b/sources/cxx-stl/gnu-libstdc++/include/iostream:72: undefined reference to `std::ios_base::Init::Init()'
/home/l/eclipse_workspace/android_bt_test1/jni/native.cpp:33: undefined reference to `std::ios_base::Init::~Init()'
My Application.mk is:
APP_OPTIM := debug
APP_MODULES := native_lab
APP_STL := gnustl_static
My Android.mk is:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native_lab
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS := -ldl -lstdc++ -llog
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include /home/l/android-ndk-r7b/sources/cxx-stl/gnu-libstdc++/include/ /home/l/android-ndk-r7b/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include
include $(BUILD_SHARED_LIBRARY)
I know this problem is very easy, but I have't found a resolution.
Could anybody help me please?

Categories

Resources