android ndk linking against libcutils.so - android

I am trying to link an executable against libcutils.so, but I get the following error:
Executable : gps_test
/home/jbrew/android_gps/jni/lib_dir//libcutils.so: undefined reference to `ioprio_set'
/home/jbrew/android_gps/jni/lib_dir//libcutils.so: undefined reference to `ioprio_get'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/gps_test] Error 1
Here is what my Android.mk file looks like:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
gps_test.c
LOCAL_LDLIBS:= -L/home/jbrew/android_gps/jni/lib_dir/ -llog -lhardware -lcutils
LOCAL_C_INCLUDES:= \
/home/jbrew/android_gps/jni/includes
LOCAL_MODULE:= gps_test
#include $(BUILD_SHARED_LIBRARY)
include $(BUILD_EXECUTABLE)
Is there a way to get the compiler to ignore these? I tried to add CFLAG --warn-unresolved-symbols, but the compiler didn't know what that flag meant.

For anyone else that has this issue, the problem was my API level. ndk-build was using android-3 to build by default. I added a default.properties file to my project path, then put "target=android-9" in that file. After this addition, I could build the executable.

Related

Android 5.1.1 - Build run-as binary

I'm trying to build a from android lollipop source the run-as binary.
I have download run-as package here : https://android.googlesource.com/platform/system/core/+archive/android-cts-5.1_r28/run-as.tar.gz
Well, here is the Android.mk code :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := run-as.c package.c
LOCAL_SHARED_LIBRARIES := libselinux
LOCAL_MODULE := run-as
LOCAL_CFLAGS := -Werror
include $(BUILD_EXECUTABLE)
When I try to build, I receive this error :
Android NDK: Module run-as depends on undefined modules: selinux
*** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)
So I add this line to my android.mk file
APP_ALLOW_MISSING_DEPS=true
Then, I download headers files from here (android_filesystem_config.h) and from here (android.h) to include proper headers files needed for run-as.c
But when I tried to build again, I have this error:
./run-as.c:158: error: undefined reference to 'selinux_android_setcontext'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I guess I miss something on the build process...
An help would be appreciate.
Thanks

Crystax NDK linker error

I'm trying to get working Crystax NDK example and have the following error (I've made up PATH/TO/MY/CRYSTAXNDK/ of course):
$ ndk-build APP_ABI=armeabi-v7a
[armeabi-v7a] Executable : test-boost
PATH/TO/MY/CRYSTAXNDK/crystax-ndk-10.3.1/sources/boost/1.59.0/include/boost/archive/detail/oserializer.hpp:88: error: undefined reference to 'boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Actually, this example is a bit outdated and I've already solved this error:
Android NDK: ERROR:PATH/TO/MY/CRYSTAXNDK/crystax-ndk-10.3.1/sources/boost/1.59.0/Android.mk:boost_atomic_static: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that PATH/TO/MY/CRYSTAXNDK/crystax-ndk-10.3.1/sources/boost/1.59.0/libs/armeabi-v7a/gnu-/libboost_atomic.a exists or that its path is correct
by adding NDK_TOOLCHAIN_VERSION=4.9 into Android.mk.
I've also replaced $(call import-module,boost/1.57.0) with $(call import-module,boost/1.59.0) to call actual version of Boost library.
So, my Android.mk looks as following:
# Android.mk
LOCAL_PATH := $(call my-dir)
NDK_TOOLCHAIN_VERSION = 4.9
include $(CLEAR_VARS)
LOCAL_MODULE := test-boost
LOCAL_SRC_FILES := test.cpp gps.cpp
LOCAL_STATIC_LIBRARIES := boost_serialization_static
include $(BUILD_EXECUTABLE)
$(call import-module,boost/1.59.0)
My crystax-ndk directory is in a system path. I understand that the cause of my problem is that NDK linker is unable to find proper Boost libraries. But I don't know how to configure it in such a way that it will automatically choose libraries depending on the target architecture.
Please help me to figure out the configuration of the linker!
Thanks.
This is bug. Shortly speaking, libboost_serialization.so was built with GNU libstdc++ v5, but when you call ndk-build, it link final binary with GNU libstdc++ v4.9, which is binary incompatible with GNU libstdc++ v5 (specifically, std::basic_string; if interested, please look here for details).
This is fixed by a7c363377 and will be included to the next bug-fix release (10.3.2). In the meantime, you can apply that patch manually on your crystax-ndk-10.3.1 file tree to solve the problem.
I ran into the same problem following the CrytaX blog tutorial. I fixed it by adding the following
# Application.mk
APP_ABI := all
NDK_TOOLCHAIN_VERSION := 5
APP_PLATFORM := android-19
The 2nd line fixed the ndk-build Boost gcc lib path error. The 3rd line fixed the "only position independent executables" problem when invoking the executable.

undefined reference to ndk boost android

I have a problem when creating an executable with ndk using the BOOST libraries in c ++ using already mentioned ndk, this is the problem
C:\Users\GENERAL\Downloads\Compressed\tcpproxy\proxy\jni>ndk-build
[armeabi] Compile++ thumb: proxy <= tcpproxy_server.cpp
[armeabi] Executable : proxy
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/sys
tem/error_code.hpp:322: error: undefined reference to 'boost::system::system_cat
egory()'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/thr
ead/exceptions.hpp:51: error: undefined reference to 'boost::system::system_cate
gory()'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/asi
o/error.hpp:225: error: undefined reference to 'boost::system::system_category()
'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/asi
o/error.hpp:225: error: undefined reference to 'boost::system::system_category()
'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/sys
tem/error_code.hpp:221: error: undefined reference to 'boost::system::generic_ca
tegory()'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/sys
tem/error_code.hpp:222: error: undefined reference to 'boost::system::generic_ca
tegory()'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//obj/local/a
rmeabi/proxy] Error 1
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/boost_1_56_0 #patch of include BOOST
LOCAL_MODULE := proxy
LOCAL_SRC_FILES := tcpproxy_server.cpp
include $(BUILD_EXECUTABLE)
Application.mk
APP_CFLAGS += -fexceptions
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS := -std=c++11
that is the error that I get when compiling. already investigate but can not find the solution so please thank your answer to be able to repair it and because generating that error thanks
You may need to add the boost_system library. You can add -lboost_system to your linker flags to find related library symbols in Android.mk (Assuming that boost is built as static):
LOCAL_STATIC_LIBRARIES = -lboost_system ...
include $(BUILD_STATIC_LIBRARY)

Android NDK build shared library

I am new in NDK and i want to use a c library in my application. I try with a simple c file and it work. I succeded to send and receive data between the two api. But when i want to introduce an existing c library i have this kind of error when i run ndk-build.
root#xxx:~/workspace/Myproject# ndk-build
Android NDK: WARNING: APP_PLATFORM android-16 is larger than android:minSdkVersion 8 in /root/workspace/MyOpus/AndroidManifest.xml
[armeabi-v7a] Compile thumb : my_manager <= myencoder.c
[armeabi-v7a] SharedLibrary : libmy_manager.so
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/libopus.so: incompatible target
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/my_manager/src/myencoder.o: in function myEncodeOpus:/root/workspace/MyOpus/jni/src/myencoder.c:81: error: undefined reference to 'opus_encoder_create'
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/my_manager/src/myencoder.o: in function myEncodeOpus:/root/workspace/MyOpus/jni/src/myencoder.c:84: error: undefined reference to 'opus_strerror'
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/my_manager/src/myencoder.o: in function myEncodeOpus:/root/workspace/MyOpus/jni/src/myencoder.c:93: error: undefined reference to 'opus_encoder_ctl'
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/my_manager/src/myencoder.o: in function myEncodeOpus:/root/workspace/MyOpus/jni/src/myencoder.c:96: error: undefined reference to 'opus_strerror'
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/my_manager/src/myencoder.o: in function myEncodeOpus:/root/workspace/MyOpus/jni/src/myencoder.c:120: error: undefined reference to 'opus_encode'
/usr/local/mes_installations/android_tool/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/my_manager/src/myencoder.o: in function myEncodeOpus:/root/workspace/MyOpus/jni/src/myencoder.c:123: error: undefined reference to 'opus_strerror'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libmy_manager.so] Error 1
How can i solve this problem? I read all the Android.mk documentation but i did not see any thing to solve it. Regards
you said you succeed to create shared library libmy_manager . in Android.mk specify the path of libmy_manager.so and the path of header files
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libmy_manager
LOCAL_SRC_FILES := libmy_manager.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include #path of header file with define
# function in libmy_manager
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := my_manager
LOCAL_SRC_FILES := my_manager.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SHARED_LIBRARIES := libmy_manager
include $(BUILD_SHARED_LIBRARY)

Android NDK cannot find -lGLESv

I am getting the following errors when I try to perform an NDK build, can anyone help me please?
I did the setup instruction exactly like what are written in "Beginning Android C++ Game Development". every step except the 9th:
"Click the NativeActivity node in the Application Nodes window and click Add once more. Enter the Name as android.app.lib_name and the Value as the LOCAL_MODULE name, which can be found in the Android.mk file in the project’s jni folder."
Errors :
10:44:23 ** Incremental Build of configuration Default for project
HelloDroid ** "C:\ndk\ndk-build.cmd" all Android NDK:
WARNING:jni/Android.mk:HelloDroid-Test: non-system libraries in linker
flags: -lGLESv Android NDK: This is likely to result in
incorrect builds. Try using LOCAL_STATIC_LIBRARIES Android NDK:
or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of
the Android NDK: current module [armeabi] SharedLibrary :
libHelloDroid-Test.so
C:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
error: cannot find -lGLESv collect2: ld returned 1 exit status
make.exe: * [obj/local/armeabi/libHelloDroid-Test.so] Error 1
10:44:23 Build Finished (took 226ms)
I found the problem.
I just needed to edit the Android.mk
it now looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hellodroid
LOCAL_SRC_FILES := hellodroid.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module, android/native_app_glue)
As the error states, there is no lib GLESv.
Which version of OpenGL ES are you using, 1 or 2?
The linker flags are -lGLESv1_CM and -lGLESv2, respectively.

Categories

Resources