Android JNI: Fail to link to static library (Undefined Reference) - android

I'm new to Android JNI and I need to use the static library (librwl.a) in my project. But I'm now having error message undefined reference. Can anyone please kindly advice what's the problem? Thanks in advance
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := staticlibrwl
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := prebuild/librwl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jrwl
LOCAL_SRC_FILES := rwl.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_WHOLE_STATIC_LIBRARIES := staticlibrwl
include $(BUILD_SHARED_LIBRARY)
rwl.cpp
#include <jni.h>
#include "include/librwl.h"
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_ms_android_pos_NativeRWL_Format
(JNIEnv * env, jobject obj){
return Format();
}
JNIEXPORT jint JNICALL Java_ms_android_pos_NativeRWL_InitActionList
(JNIEnv * env, jobject obj){
return InitActionList();
}
#ifdef __cplusplus
}
#endif
Header:
#ifdef __cplusplus
extern "C" {
#endif
extern int Format();
extern int InitActionList();
#ifdef __cplusplus
}
#endif
Error Message:
D:\Project\android-ndk-r10\ndk-build.cmd all
Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 10 in ./AndroidManifest.xml
[armeabi] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[armeabi] Compile++ thumb: jrwl <= rwl.cpp
[armeabi] SharedLibrary : libjrwl.so
D:/Project/android-ndk-r10/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-debug/jrwl/rwl.o: in function Java_ms_android_pos_NativeRWL_Format:jni/rwl.cpp:12: error: undefined reference to 'Format'
D:/Project/android-ndk-r10/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-debug/jrwl/rwl.o: in function Java_ms_android_pos_NativeRWL_InitActionList:jni/rwl.cpp:18: error: undefined reference to 'InitActionList'
collect2: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libjrwl.so] Error 1
Error Message after using ndk-build V=1 -B (Edit on 6-Aug-2014):
D:\Project\android-ndk-r10\ndk-build.cmd V=1 -B all
Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 10 in ./AndroidManifest.xml
del /f/q .\libs\armeabi\gdbserver >NUL 2>NUL
del /f/q .\libs\armeabi\gdb.setup >NUL 2>NUL
[armeabi] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
copy /b/y "D:\Project\android-ndk-r10\prebuilt\android-arm\gdbserver\gdbserver" ".\libs\armeabi\gdbserver" > NUL
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
D:/Project/android-ndk-r10/prebuilt/windows-x86_64/bin/echo.exe "set solib-search-path ./obj/local/armeabi" > ./libs/armeabi/gdb.setup
D:/Project/android-ndk-r10/prebuilt/windows-x86_64/bin/echo.exe "directory D:/Project/android-ndk-r10/platforms/android-17/arch-arm/usr/include jni/include D:/Project/android-ndk-r10/sources/cxx-stl/system/include" >> ./libs/armeabi/gdb.setup
[armeabi] Compile++ thumb: jrwl <= rwl.cpp
D:/Project/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs-debug/jrwl/rwl.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -O0 -UNDEBUG -marm -fno-omit-frame-pointer -Ijni/include -ID:/Project/android-ndk-r10/sources/cxx-stl/system/include -Ijni/include -Ijni -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -ID:/Project/android-ndk-r10/platforms/android-17/arch-arm/usr/include -c jni/rwl.cpp -o ./obj/local/armeabi/objs-debug/jrwl/rwl.o
[armeabi] StaticLibrary : libstdc++.a
del /f/q obj\local\armeabi\libstdc++.a >NUL 2>NUL
D:/Project/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ar crsD ./obj/local/armeabi/libstdc++.a
[armeabi] SharedLibrary : libjrwl.so
D:/Project/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -Wl,-soname,libjrwl.so -shared --sysroot=D:/Project/android-ndk-r10/platforms/android-17/arch-arm ./obj/local/armeabi/objs-debug/jrwl/rwl.o -Wl,--whole-archive jni/prebuild/librwl.a -Wl,--no-whole-archive ./obj/local/armeabi/libstdc++.a -lgcc -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -LD:/Project/android-ndk-r10/platforms/android-17/arch-arm/usr/lib -L./prebuild -lstdc++ -lc -lm -o ./obj/local/armeabi/libjrwl.so
D:/Project/android-ndk-r10/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-debug/jrwl/rwl.o: in function Java_ms_android_pos_NativeRWL_Format:jni/rwl.cpp:12: error: undefined reference to 'Format'
D:/Project/android-ndk-r10/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-debug/jrwl/rwl.o: in function Java_ms_android_pos_NativeRWL_InitActionList:jni/rwl.cpp:18: error: undefined reference to 'InitActionList'
collect2: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libjrwl.so] Error 1

Related

Android Vulkan linker command failed

I'm trying to use Vulkan on Android so I had installed android ndk. I saw that in Android Studio default native C++, Vulkan is included. But whenever I build I get the following error:
C:/Users/a18/AndroidStudioProjects/vulkanSMD/app/src/main/cpp/native-lib.cpp:34:
error: undefined reference to 'vkCreateInstance' clang++: error:
linker command failed with exit code 1 (use -v to see invocation)
I've tried including libvulkan.so and also tried dlopen("libvulkan.so", flags) but it is of no use.
I'm trying to get Vulkan working on android. The below code creates a vulkan instance.
#include <jni.h>
#include <string>
#include <vector>
#define VK_USE_PLATFORM_ANDROID_KHR 1
#include <vulkan/vulkan.h>
std::vector<const char *>extensions;
std::vector<const char *>layers;
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_vulkansmd_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
extensions = std::vector<const char *>({
"VK_EXT_debug_report",
"VK_KHR_surface",
});
layers = std::vector<const char *>({"VK_LAYER_LUNARG_standard_validation"});
VkInstanceCreateInfo createInfo = {};
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Vulkan is hard";
appInfo.applicationVersion = VK_VERSION_1_0;
appInfo.engineVersion = VK_VERSION_1_0;
appInfo.apiVersion = VK_VERSION_1_0 ;
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
createInfo.ppEnabledExtensionNames = extensions.data();
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledLayerNames = layers.data();
createInfo.enabledLayerCount = static_cast<uint32_t>(layers.size());
VkInstance instance;
vkCreateInstance(&createInfo, nullptr, &instance);
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
While building however I get the following error
Build command failed. Error while executing process
C:\Users\a18\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\cmake.exe
with arguments {--build
C:\Users\a18\AndroidStudioProjects\vulkanSMD\app.externalNativeBuild\cmake\debug\x86_64
--target native-lib} [1/2] Building CXX object CMakeFiles/native-lib.dir/native-lib.cpp.o [2/2] Linking CXX shared
library
C:\Users\a18\AndroidStudioProjects\vulkanSMD\app\build\intermediates\cmake\debug\obj\x86_64\libnative-lib.so
FAILED:
C:/Users/a18/AndroidStudioProjects/vulkanSMD/app/build/intermediates/cmake/debug/obj/x86_64/libnative-lib.so
cmd.exe /C "cd . &&
C:\Users\a18\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe
--target=x86_64-none-linux-android26 --gcc-toolchain=C:/Users/a18/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64
--sysroot=C:/Users/a18/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot
-fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o C:\Users\a18\AndroidStudioProjects\vulkanSMD\app\build\intermediates\cmake\debug\obj\x86_64\libnative-lib.so
CMakeFiles/native-lib.dir/native-lib.cpp.o -llog -latomic -lm && cd
."
C:/Users/a18/AndroidStudioProjects/vulkanSMD/app/src/main/cpp/native-lib.cpp:34:
error: undefined reference to 'vkCreateInstance' clang++: error:
linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

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

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 .

Linker error: undefined reference to `EVP_cast5_ecb'

I'm trying to compile openssl with cast support but I instead get this error:
SharedLibrary : libcrypto.so
./obj/local/armeabi/objs/crypto/evp/c_allc.o: In function `OpenSSL_add_all_ciphers':
~/testandroid/libssl/jni/crypto/evp/c_allc.c:143: undefined reference to `EVP_cast5_ecb'
~/testandroid/libssl/jni/crypto/evp/c_allc.c:144: undefined reference to `EVP_cast5_cfb64'
~/testandroid/libssl/jni/crypto/evp/c_allc.c:145: undefined reference to `EVP_cast5_ofb'
~/testandroid/libssl/jni/crypto/evp/c_allc.c:146: undefined reference to `EVP_cast5_cbc'
./obj/local/armeabi/objs/crypto/evp/e_old.o: In function `EVP_cast5_cfb':
~/testandroid/libssl/jni/crypto/evp/e_old.c:104: undefined reference to `EVP_cast5_cfb64'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libcrypto.so] Error 1
EVP_cast5_ecb and friends are all defined in ~/testandroid/libssl/jni/crypto/evp/evp.h and in ~/testandroid/libssl/jni/include/evp.h
#ifndef OPENSSL_NO_CAST
const EVP_CIPHER *EVP_cast5_ecb(void);
const EVP_CIPHER *EVP_cast5_cbc(void);
const EVP_CIPHER *EVP_cast5_cfb64(void);
# define EVP_cast5_cfb EVP_cast5_cfb64
const EVP_CIPHER *EVP_cast5_ofb(void);
#endif
In crypto/Android.mk
local_src_files := \
evp/c_allc.c \
evp/e_old.c \
# And a whole bunch of other c files
local_c_includes := \
$(APP_PROJECT_PATH) \
$(APP_PROJECT_PATH)/crypto/asn1 \
$(APP_PROJECT_PATH)/crypto/evp \ # evp.h is located here
$(APP_PROJECT_PATH)/include \
$(APP_PROJECT_PATH)/include/openssl # Another evp.h is also located here
include $(CLEAR_VARS)
include $(LOCAL_PATH)/../android-config.mk
ifeq ($(TARGET_ARCH),arm)
LOCAL_NDK_VERSION := 5
LOCAL_SDK_VERSION := 9
# Use the NDK prebuilt libz and libdl.
LOCAL_LDFLAGS += -lz -ldl
else
LOCAL_SHARED_LIBRARIES += libz libdl
endif
LOCAL_SRC_FILES += $(local_src_files)
LOCAL_CFLAGS += $(local_c_flags)
LOCAL_C_INCLUDES += $(local_c_includes)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:= libcrypto
include $(BUILD_SHARED_LIBRARY)
I'm probably missing something very trivial here, since I'm new to Android and C in general, so be nice :)
EDIT: I saw that there is a Makefile for cast. I'm guessing there is a whole load of linking magic going on at the very bottom of the original Makefile. How would I do something equivalent for Android?
#
# OpenSSL/crypto/cast/Makefile
#
DIR= cast
TOP= ../..
CC= cc
CPP= $(CC) -E
INCLUDES=
CFLAG=-g
MAKEFILE= Makefile
AR= ar r
CAST_ENC=c_enc.o
CFLAGS= $(INCLUDES) $(CFLAG)
ASFLAGS= $(INCLUDES) $(ASFLAG)
AFLAGS= $(ASFLAGS)
GENERAL=Makefile
TEST=casttest.c
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC=c_skey.c c_ecb.c c_enc.c c_cfb64.c c_ofb64.c
LIBOBJ=c_skey.o c_ecb.o $(CAST_ENC) c_cfb64.o c_ofb64.o
SRC= $(LIBSRC)
EXHEADER= cast.h
HEADER= cast_s.h cast_lcl.h $(EXHEADER)
ALL= $(GENERAL) $(SRC) $(HEADER)
top:
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
all: lib
lib: $(LIBOBJ)
$(AR) $(LIB) $(LIBOBJ)
$(RANLIB) $(LIB) || echo Never mind.
#touch lib
cast-586.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
$(PERL) asm/cast-586.pl $(PERLASM_SCHEME) $(CLAGS) $(PROCESSOR) > $#
files:
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
links:
#$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
#$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
#$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
install:
#[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
#headerlist="$(EXHEADER)"; for i in $$headerlist ; \
do \
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
done;
tags:
ctags $(SRC)
tests:
lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
depend:
#[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
dclean:
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
mv -f Makefile.new $(MAKEFILE)
clean:
rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_cfb64.o: ../../e_os.h ../../include/openssl/cast.h
c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
c_cfb64.o: c_cfb64.c cast_lcl.h
c_ecb.o: ../../e_os.h ../../include/openssl/cast.h
c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
c_ecb.o: ../../include/openssl/opensslv.h c_ecb.c cast_lcl.h
c_enc.o: ../../e_os.h ../../include/openssl/cast.h
c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
c_enc.o: c_enc.c cast_lcl.h
c_ofb64.o: ../../e_os.h ../../include/openssl/cast.h
c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
c_ofb64.o: c_ofb64.c cast_lcl.h
c_skey.o: ../../e_os.h ../../include/openssl/cast.h
c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
c_skey.o: c_skey.c cast_lcl.h cast_s.h

Categories

Resources