NDK. Protobuf library linking - android

Good day. I compiled protobuf 2.4.1 library with ndk. Script I took from that post:
How to build protocol buffer by Android NDK
But when I try to link my library to test cocos2d-x project I gets next errors:
SharedLibrary : libgame.so
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::RegistrationRequest const* google::protobuf::internal::dynamic_cast_if_available<promowall::RegistrationRequest const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::RegistrationResponse const* google::protobuf::internal::dynamic_cast_if_available<promowall::RegistrationResponse const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::InstallIntentRequest const* google::protobuf::internal::dynamic_cast_if_available<promowall::InstallIntentRequest const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::ItemRequest const* google::protobuf::internal::dynamic_cast_if_available<promowall::ItemRequest const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::ItemResponse const* google::protobuf::internal::dynamic_cast_if_available<promowall::ItemResponse const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o:/usr/include/google/protobuf/generated_message_reflection.h:396: more undefined references to `typeinfo for google::protobuf::Message' follow
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libgame.so] Error 1
As I can see from this log compiler can't find message type. But source file message.cc and message_lite.cc were included in libprotobuf.so library.
Source code of my test application Android.mk listed below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := protobuf
LOCAL_MODULE_FILENAME := libprotobuf
LOCAL_SRC_FILES := libprotobuf.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/protocol.pb.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_SHARED_LIBRARIES := protobuf
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)
I will be very grateful for any help :)

Your log suggests that you didn't turn on RTTI support. See https://developer.android.com/ndk/guides/cpp-support#rtti for instructions:
To enable RTTI across your whole application in ndk-build, add the following line to your Application.mk file:
APP_CPPFLAGS := -frtti
To enable RTTI for a single ndk-build module, add the following line to the given module in its Android.mk:
LOCAL_CPP_FEATURES := rtti
Alternatively, you can use:
LOCAL_CPPFLAGS := -frtti

Related

Android NDK and CrystaX doesn't recognize std::index_sequence

I try to compile this code that I copied from cppreference.com
#include <iostream>
#include <tuple>
#include <utility>
template<typename Func, typename Tup, std::size_t... index>
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
{
return func(std::get<index>(std::forward<Tup>(tup))...);
}
template<typename Func, typename Tup>
decltype(auto) invoke(Func&& func, Tup&& tup)
{
constexpr auto Size = std::tuple_size<typename std::decay<Tup>::type>::value;
return invoke_helper(std::forward<Func>(func),
std::forward<Tup>(tup),
std::make_index_sequence<Size>{});
}
void foo(int a, const std::string& b, float c)
{
std::cout << a << " , " << b << " , " << c << '\n';
}
my Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=test
LOCAL_SRC_FILES :=../../test.cpp
LOCAL_STATIC_LIBRARIES := c++_static
LOCAL_CFLAGS := -std=c++14
include $(BUILD_STATIC_LIBRARY)
my Application.mk :
APP_MODULES := test
APP_OPTIM := release
APP_ABI := armeabi armeabi-v7a mips x86
NDK_TOOLCHAIN_VERSION=clang
APP_STL := c++_static
using NDK r13b, I got this errors :
jni/../../test.cpp:6:10: warning: 'decltype(auto)' type specifier is a C++14 extension [-Wc++14-extensions]
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
^
jni/../../test.cpp:6:59: error: no type named 'index_sequence' in namespace 'std'
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
~~~~~^
jni/../../test.cpp:6:73: error: expected ')'
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
^
jni/../../test.cpp:6:29: note: to match this '('
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
^
jni/../../test.cpp:6:1: error: deduced return types are a C++14 extension
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
^
jni/../../test.cpp:12:10: warning: 'decltype(auto)' type specifier is a C++14 extension [-Wc++14-extensions]
decltype(auto) invoke(Func&& func, Tup&& tup)
^
jni/../../test.cpp:12:1: error: deduced return types are a C++14 extension
decltype(auto) invoke(Func&& func, Tup&& tup)
^
jni/../../test.cpp:17:31: error: no member named 'make_index_sequence' in namespace 'std'
std::make_index_sequence<Size>{});
~~~~~^
jni/../../test.cpp:17:55: error: initializer list cannot be used on the right hand side of operator '>'
std::make_index_sequence<Size>{});
^~~
jni/../../test.cpp:28:5: error: no matching function for call to 'invoke'
invoke(foo, args);
I also try using crystax 10.3.2 and got identical errors. It seems that my flag -std=c++14 doesn't seems to take effect. The errors complaint about decltyp(auto), auto return value and index_sequence. All are c++ 14 features.
Any suggestion ?
I try run ndk-build V=1 and this is the verbose output
F:/Library/android-ndk-r13b/build//../toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -MMD -MP -MF ./obj/local/armeabi/objs/test/__/__/test.o.d -gcc-toolchain F:/Library/android-ndk-r13b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -g -target armv5te-none-linux-androideabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -DNDEBUG -IF:/Library/android-ndk-r13b/build//../sources/cxx-stl/llvm-libc++/include -IF:/Library/android-ndk-r13b/build//../sources/cxx-stl/llvm-libc++/../../android/support/include -IF:/Library/android-ndk-r13b/build//../sources/cxx-stl/llvm-libc++abi/include -Ijni -DANDROID -std=c++14 -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -isystem F:/Library/android-ndk-r13b/build//../platforms/android-9/arch-arm/usr/include -c jni/../../test.cpp -o ./obj/local/armeabi/objs/test/__/__/test.o
I see that both -std=c++14 and -std=c++11 is specified. Maybe the -std=c++11 take precedence ? I don't where that come from though.
I found the solution, I just need to specify -std=c++14 in Application.mk instead in Android.mk. So now, the Android.mk is
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=test
LOCAL_SRC_FILES :=../../test.cpp
LOCAL_STATIC_LIBRARIES := c++_static
include $(BUILD_STATIC_LIBRARY)
and Application.mk :
APP_MODULES := test
APP_OPTIM := release
APP_ABI := armeabi armeabi-v7a mips x86
NDK_TOOLCHAIN_VERSION=clang
APP_STL := c++_static
APP_CPPFLAGS += -std=c++14

Using gstreamer plugins bad in android

I am trying to show h264 encodes streams inside an android application using the GStreamer SDK and Android NDK.
My Android.mk looks like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := App
LOCAL_SRC_FILES := App.cpp
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
ifndef GSTREAMER_ROOT
ifndef GSTREAMER_ROOT_ANDROID
$(error GSTREAMER_ROOT_ANDROID is not defined!)
endif
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)
endif
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build/
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_SYS) $(GSTREAMER_PLUGINS_EFFECTS) $(GSTREAMER_PLUGINS_NET)
GSTREAMER_EXTRA_DEPS := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk
Beacause of missing plugins-bad I get the following error:
priv_gst_parse_yyparse no element "h264parse"
My pipe looks like the following:
udpsrc address=192.168.0.1 port=5000 ! application/x-rtp, encoding-name=H264, payload=96 ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink
So how can I include the gstreamer-plugins-bad into android build?
Try adding this line instead the one you have:
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS) $(GSTREAMER_PLUGINS_CODECS_RESTRICTED)
Specifically this one should do the job $(GSTREAMER_PLUGINS_CODECS_RESTRICTED)
You can add this line :
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS) $(GSTREAMER_PLUGINS_CODECS_RESTRICTED) $(GSTREAMER_PLUGINS_EFFECTS)
in your path : app/jni/Android.mk

Build Android OpenCV and FastCV

I am having issues when building OpenCV and FastCV as static libs. Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include /Users/Razvan/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
USE_OPENGL_ES_1_1 := false
ifeq ($(USE_OPENGL_ES_1_1), true)
OPENGLES_LIB := -lGLESv1_CM
OPENGLES_DEF := -DUSE_OPENGL_ES_1_1
else
OPENGLES_LIB := -lGLESv2
OPENGLES_DEF := -DUSE_OPENGL_ES_2_0
endif
LOCAL_MODULE := drive_assist
LOCAL_SRC_FILES += jni_part.cpp GridTracking.cpp CameraRendererRGB565GL2.cpp FastCVSampleRenderer.cpp CameraUtil.cpp
LOCAL_LDLIBS += -llog -ldl $(OPENGLES_LIB) -lfastcv
LOCAL_CFLAGS += -Wno-write-strings $(OPENGLES_DEF) -ffast-math -O3 -fopenmp -funroll-loops
LOCAL_LDFLAGS +=-O3 -fopenmp
LOCAL_CPPFLAGS := -O3 -flto -ffunction-sections -fdata-sections
LOCAL_CPPFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
LOCAL_CPPFLAGS += -fomit-frame-pointer -funroll-loops -ffast-math
LOCAL_CPPFLAGS += -mfloat-abi=softfp -DFPM_ARM -DNDEBUG
LOCAL_STATIC_LIBRARIES += libfastcv
LOCAL_SHARED_LIBRARIES := liblog libGLESv2
include $(BUILD_SHARED_LIBRARY)
I get weird undefined reference errors in the OpenCV native library, for example:
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:353: error: undefined reference to 'cv::Mat::create(int, int const*, int)'
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
/Users/Razvan/Android/OpenCV-2.4.11-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
The strange thing is that if I remove the FastCV stuff, OPenCV will compile and work perfectly. I do NOT want to use dynamic linking and the OpenCV manager. Does anyone have any suggestions for my issue?
Thanks!
Solved by changing the shared libs in Android.mk as follows:
LOCAL_SHARED_LIBRARIES += lopencv_java liblog libGLESv2

Cannot find libxml2 in android ndk project

Good day Everyone. I have wasted almost a week now figuring what's wrong when i try adding libxml2 to my android ndk project.
LOCAL_PATH := $(call my-dir)
#BUILDING LIBXML2
include $(CLEAR_VARS)
LOCAL_MODULE := xml2
LOCAL_SRC_FILES := $(LOCAL_PATH)/libxml2/libxml2.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libxml2/include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libxml2/include
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
include $(BUILD_SHARED_LIBRARY)
#BUILDING SOME SPICE CODES
include $(CLEAR_VARS)
LIB_PATH := $(LOCAL_PATH)/../../libs/armeabi
SPICE_CLIENT_ANDROID_DEPS := $(LOCAL_PATH)/../libs/deps
spice_objs := \
$(SPICE_CLIENT_ANDROID_DEPS)/lib/libssl.a \
$(SPICE_CLIENT_ANDROID_DEPS)/lib/libcrypto.a \
$(SPICE_CLIENT_ANDROID_DEPS)/lib/libcelt051.a
LOCAL_MODULE := spice
LOCAL_SRC_FILES := channel-record.c channel-playback.c channel-cursor.c \
spice-cmdline.c coroutine_gthread.c spice-util.c \
spice-session.c spice-channel.c spice-marshal.c spice-glib-enums.c \
common/generated_client_demarshallers.c common/generated_client_demarshallers1.c \
common/generated_client_marshallers.c common/generated_client_marshallers1.c \
gio-coroutine.c channel-base.c channel-main.c spice-proxy.c bio-gsocket.c glib-compat.c \
channel-display.c channel-display-mjpeg.c channel-inputs.c decode-glz.c \
decode-jpeg.c decode-zlib.c wocky-http-proxy.c channel-port.c spice-client.c spice-audio.c \
common/mem.c common/marshaller.c common/canvas_utils.c common/backtrace.c \
common/sw_canvas.c common/pixman_utils.c common/lines.c common/rop3.c common/quic.c \
common/lz.c common/region.c common/ssl_verify.c common/log.c spice-gstaudio.c
LOCAL_LDLIBS += $(spice_objs) \
-ljnigraphics -llog -ldl -lstdc++ -lz -lc \
-malign-double -malign-loops
LOCAL_LDLIBS += -L$(LIB_PATH) -lgstreamer_android
LOCAL_CPPFLAGS += -DG_LOG_DOMAIN=\"GSpice\" \
-DSW_CANVAS_CACHE \
-DSPICE_GTK_LOCALEDIR=\"/usr/local/share/locale\" \
-DHAVE_CONFIG_H -UHAVE_SYS_SHM_H -DSW_CANVAS_CACHE \
-D_REENTRANT -DWITH_GSTAUDIO
LOCAL_C_INCLUDES += $(LOCAL_PATH)/common \
$(SPICE_CLIENT_ANDROID_DEPS)/include
LOCAL_CFLAGS := $(LOCAL_CPPFLAGS) \
-std=gnu99 -Wall -Wno-sign-compare -Wno-deprecated-declarations -Wl,--no-undefined \
-fPIC -DPIC -O3 -funroll-loops -ffast-math
LOCAL_EXPORT_CFLAGS += $(LOCAL_CFLAGS)
LOCAL_EXPORT_LDLIBS += $(LOCAL_LDLIBS)
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_ARM_MODE := arm
include $(BUILD_STATIC_LIBRARY)
#BUILDING SOME MINE C CODE --------Here i add Mine C file and xml2 for it
include $(CLEAR_VARS)
LOCAL_MODULE := start-spice
LOCAL_SRC_FILES := start-spice.c
LOCAL_SHARED_LIBRARIES= xml2
include $(BUILD_SHARED_LIBRARY)
#BUILDING SPICE ANDROID
include $(CLEAR_VARS)
LOCAL_MODULE := spice-android
LOCAL_SRC_FILES := android/android-service.c android/android-spicy.c android/android-spice-widget.c \
android/android-io.c
LOCAL_STATIC_LIBRARIES := spice
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
ifndef GSTREAMER_SDK_ROOT
ifndef GSTREAMER_SDK_ROOT_ANDROID
$(error GSTREAMER_SDK_ROOT_ANDROID is not defined!)
endif
GSTREAMER_SDK_ROOT := $(GSTREAMER_SDK_ROOT_ANDROID)
endif
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_SDK_ROOT)/share/gst-android/ndk-build/
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_SYS) jpeg
GSTREAMER_EXTRA_DEPS := glib-2.0 gthread-2.0 pixman-1 gstreamer-app-0.10
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer.mk
So even after I add xml2.so as shared library to my project - nothing happens. It strill cannot find libs and gives me tons of this
[armeabi] SharedLibrary : libstart-spice.so
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function create_request:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:251: error: undefined reference to 'xmlNewDoc'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function create_request:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:252: error: undefined reference to 'xmlNewNode'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function create_request:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:253: error: undefined reference to 'xmlNodeSetContent'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function create_request:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:254: error: undefined reference to 'xmlDocSetRootElement'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function create_request:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:255: error: undefined reference to 'xmlDocDumpFormatMemory'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function create_request:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:256: error: undefined reference to 'xmlFreeDoc'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:144: error: undefined reference to 'xmlReadMemory'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:153: error: undefined reference to 'xmlDocGetRootElement'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:163: error: undefined reference to 'xmlHasProp'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:170: error: undefined reference to 'xmlHasProp'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:172: error: undefined reference to 'xmlGetProp'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:182: error: undefined reference to 'xmlHasProp'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:184: error: undefined reference to 'xmlGetProp'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:221: error: undefined reference to 'xmlFreeDoc'
/opt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/objs/start-spice/start-spice.o: in function Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword:/opt/Test6/bVNC/eclipse_projects/bVNC/jni/src/start-spice.c:234: error: undefined reference to 'xmlFreeDoc'
collect2: ld returned 1 exit status
make: *** [/opt/Test6/bVNC/eclipse_projects/bVNC/obj/local/armeabi/libstart-spice.so] Error 1
ะก code header in start-spice looks something like this:
#include <jni.h>
#include <android/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <libxml/parser.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
And i in java code i add:
static
{
System.loadLibrary("start-spice");
}
Would be really really gratefull if someone helped!
If you have the prebuilt static library for Android in $(LOCAL_PATH)/libxml2/libxml2.a, you can use it as is in your spice-android project,
LOCAL_STATIC_LIBRARIES += xml2
Instead of include $(BUILD_SHARED_LIBRARY) for xml2, use
LOCAL_SRC_FILES := libxml2/libxml2.a
include $(PREBUILT_STATIC_LIBRARY)
If you have a strong reason to use xml2 as a separate shared library, you need to add call
System.loadLibrary("xml2");
to your Java code (before loading libspice-android.so) and replace LOCAL_SRC_FILES := $(LOCAL_PATH)/libxml2/libxml2.a with
LOCAL_WHOLE_STATIC_LIBRARIES := $(LOCAL_PATH)/libxml2/libxml2.a
This is issue of linking shared libraries, you need to add LOCAL_LDLIBS += $(LIB_PATH) -lxm2 just before LOCAL_SHARED_LIBRARIES= xml2 .

java.lang.unsatisfiedLinkError lib not found :(failed to link mylib.so)

i've successfully cross compiled a c++ library to the android plateform using the android ndk standalone toolchain.
i've created a new android application project into Eclipse with a jni dolder and Android.mk file and when i do an ndk-build the building goes well and it adds mylib.so to libs/armeabi folder
The problem is when i do a System.loadLibrary("mylibname");
i get the following error in the logcat:
Unable to dlopen(/data/data/com.oussama.firsttry/lib/libdash.so): Cannot load library: link_image[1995]: failed to link libdash.so
that cause a java.lang.UnsatisfiedLinkError: my lib not found**.
There must be a library that my lib depends on and the emulator can't load it so i've done a readelf -d mylib.so and here is the result:
Dynamic section at offset 0x1617c4 contains 26 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000e (SONAME) Library soname: [libdash.so]
0x00000010 (SYMBOLIC) 0x0
0x0000000f (RPATH) Library rpath: [/home/oussama064/libdash/libdash/../../neededLibs]
0x00000019 (INIT_ARRAY) 0x157268
0x0000001b (INIT_ARRAYSZ) 172 (bytes)
0x0000001a (FINI_ARRAY) 0x157314
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000004 (HASH) 0xf4
0x00000005 (STRTAB) 0x10f58
0x00000006 (SYMTAB) 0x50b8
0x0000000a (STRSZ) 134112 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x1618b4
0x00000002 (PLTRELSZ) 1096 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x40dd8
0x00000011 (REL) 0x31b38
0x00000012 (RELSZ) 62112 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000018 (BIND_NOW)
0x6ffffffb (FLAGS_1) Flags: NOW
0x6ffffffa (RELCOUNT) 7738
0x00000000 (NULL) 0x0
Here is my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) LOCAL_MODULE := libcurl LOCAL_SRC_FILES :=
../../../../neededLibs/libcurl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := libxml LOCAL_SRC_FILES :=
../../../../neededLibs/libxml2.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := libz LOCAL_SRC_FILES :=
../../../../neededLibs/libz.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := m LOCAL_SRC_FILES :=
libm.so include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS)
LOCAL_MODULE := dl LOCAL_SRC_FILES := libdl.so
include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE
:= c LOCAL_SRC_FILES := libc.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := d LOCAL_SRC_FILES := libdash.so
LOCAL_SHARED_LIBRARIES := c m dl
LOCAL_STATIC_LIBRARIES := libz libxml libcurl include
$(PREBUILT_SHARED_LIBRARY)
i'am really stuck now and i can't figure out what is the missing library
When i do an ndk-build V=1 -B i get the following result:
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/lib*.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/lib*.so
/home/oussama064/Android/workspace/FirstTry/libs/mips/lib*.so
/home/oussama064/Android/workspace/FirstTry/libs/x86/lib*.so
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdbserver
/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdbserver
/home/oussama064/Android/workspace/FirstTry/libs/mips/gdbserver
/home/oussama064/Android/workspace/FirstTry/libs/x86/gdbserver
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdb.setup
/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdb.setup
/home/oussama064/Android/workspace/FirstTry/libs/mips/gdb.setup
/home/oussama064/Android/workspace/FirstTry/libs/x86/gdb.setup
make: Circular obj/local/armeabi/libm.so <- obj/local/armeabi/libm.so dependency
dropped.
make: Circular obj/local/armeabi/libm.so <- obj/local/armeabi/libc.so dependency
dropped.
make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libm.so dependency
dropped.
make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libc.so dependency
dropped.
make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libdl.so dependency
dropped.
Prebuilt : libdl.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdl.so
obj/local/armeabi/libdl.so
Prebuilt : libm.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libm.so obj/local/armeabi/libm.so
make: Circular obj/local/armeabi/libc.so <- obj/local/armeabi/libc.so dependency dropped.
Prebuilt : libc.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libc.so obj/local/armeabi/libc.so
Install : libc.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so
install -p ./obj/local/armeabi/libc.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so
Prebuilt : libxml2.a <=
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/
cp -f
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libxml2.a
obj/local/armeabi/libxml2.a
Prebuilt : libcurl.a <=
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/
cp -f
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libcurl.a
obj/local/armeabi/libcurl.a
Prebuilt : libdash.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdash.so
obj/local/armeabi/libdash.so
Install : libdash.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
install -p ./obj/local/armeabi/libdash.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
Install : libdl.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
install -p ./obj/local/armeabi/libdl.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
Install : libm.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
install -p ./obj/local/armeabi/libm.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
I would be thankfull if any one can help me.
You should use the system versions of libm, libc and libdl shared libraries,
LOCAL_LDLIBS := -lm -ldl
If you can't, link them statically.

Categories

Resources