I recently need to set specific build-id to a elf file in Android.
Firstly,I use shell command like this:
arm-linux-androideabi-gcc -pie -Wl,--build-id=0xFFFFFFFF --sysroot /home/chengyi/code/android_6.0.1_bullhead/prebuilts/ndk/9/platforms/android-18/arch-arm main.c
readelf -n a.out.everthing is OK.
Above is only a demo,I need to set build-id in Android.mk at last.here is my Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
main.cpp
LOCAL_SHARED_LIBRARIES := \
liblog \
libdl \
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/ \
bionic \
LOCAL_MODULE:= a.out
LOCAL_CXXFLAGS := \
-pie -Wl,--build-id=0xFFFFFFFFFFFFFFFFFF --sysroot /home/chengyi/code/android_6.0.1_bullhead/prebuilts/ndk/9/platforms/android-18/arch-arm \
include $(BUILD_EXECUTABLE)
The output elf file has a constant build-id,no matter how I strive.
Is there any method to set a specific build-id to elf file in Android.mk?
Thanks a lot for any help.
If you want to set build-id by Android.mk. Don't use variable LOCAL_CXXFLAGS or LOCAL_CFLAGS.
build-id is sent to linker,so you need to use LOCAL_LDFLAGS like this:
LOCAL_LDFLAGS += -Wl,--build-id=0xFFFFFFFFFFFFFF
Related
I am currently trying to build a native module using Android's NDK. My project consists of several source files (e.g.: FILENAME.c) and for each of them I need to declare a define in their CFLAGS (-DOPERATION_FILENAME).
In order to do that I need to dynamically fetch the name of the current target file of the Android NDK's cross-compiler and use it to for the define value.
I could not find any information about how to do this and the Makefile way (CFLAGS += -DOPERATION_echo $* | sed 's/_$$//') does not apply/work here.
My current Android.mk looks like this:
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libmpn
LOCAL_SRC_FILES := \
<cut>
LOCAL_CFLAGS := \
-std=gnu99 \
-DHAVE_CONFIG_H \
-D__GMP_WITHIN_GMP \
-O2 \
-pedantic \
-fomit-frame-pointer \
-mfloat-abi=softfp \
-DOPERATION_`echo $* | sed 's/_$$//'`
include $(BUILD_SHARED_LIBRARY)
Does anyone know of a working way to get the file name of the current cross-compiler target in Android.mk? Thanks!
In the beginning of your Android.mk, add the line that redefines get-src-file-target-cflags, like here:
get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1) -DOPERATION_$(basename $1)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := t.cpp qq.c
LOCAL_MODULE := tm
LOCAL_LDLIBS := -latomic
include $(BUILD_SHARED_LIBRARY)
You can put this line in Application.mk, if you choose.
I am building AOSP Kitkat (4.4) and trying to find the Android.mk file that defines the libnfc-nci module. The libnfc_nci_jni module depends on this local shared library (Android.mk included below) and I want to see the source that generates this .so file. I know that the nfc.h exists in /hardware/libhardware/include/hardware/nfc.h, but that is only the headers.
As far as I know, the available tools for searching android source code are cgrep, jgrep, and resgrep. However, (to my knowledge) these don't search Android.mk files. Is there a tool that I'm missing that I can use to find the directory that contains the module libnfc-nci?
Here is the Android.mk for libnfc_nci_jni (found in /packages/apps/Nfc/nci/jni/Android.mk)
VOB_COMPONENTS := external/libnfc-nci/src
NFA := $(VOB_COMPONENTS)/nfa
NFC := $(VOB_COMPONENTS)/nfc
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
ifneq ($(NCI_VERSION),)
LOCAL_CFLAGS += -DNCI_VERSION=$(NCI_VERSION) -O0 -g
endif
LOCAL_CFLAGS += -Wall -Wextra
define all-cpp-files-under
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find $(1) -name "*.cpp" -and -not -name ".*") \
)
endef
LOCAL_SRC_FILES:= $(call all-cpp-files-under, .)
LOCAL_C_INCLUDES += \
bionic \
bionic/libstdc++ \
external/stlport/stlport \
external/libxml2/include \
external/icu4c/common \
frameworks/native/include \
libcore/include \
$(NFA)/include \
$(NFA)/brcm \
$(NFC)/include \
$(NFC)/brcm \
$(NFC)/int \
$(VOB_COMPONENTS)/hal/include \
$(VOB_COMPONENTS)/hal/int \
$(VOB_COMPONENTS)/include \
$(VOB_COMPONENTS)/gki/ulinux \
$(VOB_COMPONENTS)/gki/common
LOCAL_SHARED_LIBRARIES := \
libicuuc \
libnativehelper \
libcutils \
libutils \
liblog \
libnfc-nci \
libstlport
LOCAL_STATIC_LIBRARIES := libxml2
LOCAL_MODULE := libnfc_nci_jni
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
I am running Ubuntu 14.04
I found libnfc-nci in /external/libnfc-nci after some more googling. It seems there is no better tool to search aosp for a module than google (unless you write your own script).
As Gabe Sechan noted, a grep solution is possible. Here is the command I used that seemed to do the trick (working directory is the root of AOSP).
grep -inIEr "LOCAL_MODULE := libnfc-nci" .
You should try :
godir libnfc-nci
It should give you options in case thete ae several such directories
the makefiles i got from the git repo are looking like this:
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../../../Include/ \
$(LOCAL_PATH)/../../../../Source/ \
$(LOCAL_PATH)/../../../../Source/XnCommon \
$(LOCAL_PATH)/../../../../Source/External/LibJPEG \
LOCAL_CFLAGS := -fvisibility=hidden -DXN_FORMATS_EXPORTS
LOCAL_LDFLAGS += -Wl,--export-dynamic --dynamic-linker
LOCAL_SHARED_LIBRARIES := OpenNI libusb XnCore
LOCAL_PREBUILT_LIBS := libc
LOCAL_MODULE := XnFormats
ok the pushed the makefiles with a little syntax error - it worked like this (no space,comma)
LOCAL_LDFLAGS += -Wl,--export-dynamic,--dynamic-linker
This is my complete Android.mk file, when I try to build this, I get a linker problem (see further down)
LOCAL_PATH := $(call my-dir)
#
# Opus - low-latency audio codec
#
include $(CLEAR_VARS)
LOCAL_DIR := opus-1.0.3
LOCAL_MODULE := opus
LOCAL_CELT_SOURCES := \
$(LOCAL_DIR)/celt/bands.c \
...
LOCAL_SILK_SOURCES := \
$(LOCAL_DIR)/silk/CNG.c \
...
LOCAL_SILK_SOURCES_FIXED := \
$(LOCAL_DIR)/silk/fixed/LTP_analysis_filter_FIX.c \
...
LOCAL_SILK_SOURCES_FLOAT := \
$(LOCAL_DIR)/silk/float/apply_sine_window_FLP.c \
...
LOCAL_OPUS_SOURCES := \
$(LOCAL_DIR)/src/opus.c \
...
LOCAL_CFLAGS := -DNONTHREADSAFE_PSEUDOSTACK
LOCAL_C_INCLUDES := \
$(LOCAL_DIR)/include \
$(LOCAL_DIR)/celt \
$(LOCAL_DIR)/silk \
$(LOCAL_DIR)/silk/fixed \
$(LOCAL_DIR)/silk/float
LOCAL_SRC_FILES := $(LOCAL_CELT_SOURCES) \
$(LOCAL_SILK_SOURCES) \
$(LOCAL_SILK_SOURCES_FIXED) \
$(LOCAL_SILK_SOURCES_FLOAT)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_DIR)/include
include $(BUILD_STATIC_LIBRARY)
################
include $(CLEAR_VARS)
LOCAL_MODULE := audio-client-jni
LOCAL_SRC_FILES := audio-client-jni.cpp
# low latency codec
LOCAL_STATIC_LIBRARIES += opus
# for native audio
LOCAL_LDLIBS += -lOpenSLES
# for logging
LOCAL_LDLIBS += -llog
# for native asset manager
LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)
To rule out that there's a problem with the way opus is being built I've done the exact same thing using a different build system called tundra and it compliles just fine on Windows using MSVC++.
Here's the linker command and errors (I've formatted the command-line for readability)
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++
-Wl,-soname,libaudio-client-jni.so
-shared
--sysroot=C:/Projects/android-ndk-r8e/platforms/android-14/arch-arm
C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o
C:/Projects/workspace/AudioClient//obj/local/armeabi/libopus.a
C:/Projects/workspace/AudioClient//obj/local/armeabi/libstdc++.a
-lgcc
-no-canonical-prefixes
-Wl,--no-undefined
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-LC:/Projects/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib
-lOpenSLES
-llog
-landroid
-lstdc++
-lc
-lm
-o C:/Projects/workspace/AudioClient//obj/local/armeabi/libaudio-client-jni.so
errors follow
C:/Projects/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: C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o: in function (anonymous namespace)::AuClient::ReceiveThenEnqueue():C:/Projects/workspace/AudioClient//jni/audio-client-jni.cpp:419: error: undefined reference to 'opus_decode'
C:/Projects/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: C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o: in function InitializeThread:C:/Projects/workspace/AudioClient//jni/audio-client-jni.cpp:387: error: undefined reference to 'opus_decoder_create'
I need a second pair of eyes on this, it's definetly linking audio-client-jni.o before libopus.a but if that is the issue I don't understand how to modify the makefile to get the desiered result. The opus.h API is defined with extern "C" when included in a C++ app. No luck so far.
Thanks to #AlexCohn for the assist, obviously there wasn't anything wrong, instead all the source files wasn't included properly, slight overlook from my part.
In my case, I wasn't sure how I should set things up to be able to run the bin util commands, luckily, it's as simple as:
"C:\Projects\android-ndk-r8e\toolchains\arm-linux-androideabi-4.6\prebuilt\windows-x86_64\bin\arm-linux-androideabi-nm.exe" "C:\Projects\workspace\AudioClient\obj\local\armeabi\libopus.a"
I just picked what seemed reasonable from the prebuilt toolchain.
With the output from nm I could verify that the exports weren't there. After closer inspection I noticed I had forgotten to include $(LOCAL_OPUS_SOURCES) in my LOCAL_C_INCLUDES. Fixing that, fixed the problem.
I am trying to compile tesseract for android using android ndk r5, code of tesseract is obtained by checking out http://code.google.com/p/tesseract-android-tools/, i am unable to compile tesseract and got errors,
Install : libjpeg.so => libs/armeabi/libjpeg.so
make: *** No rule to make target `//cygdrive/e/DemoExamples_WorkSpace/tesseract-android-tools/jni/../external/leptonlib-1.66/src/adaptmap.c', needed b
y `/cygdrive/e/DemoExamples_WorkSpace/tesseract-android-tools/obj/local/armeabi/objs/lept//cygdrive/e/DemoExamples_WorkSpace/tesseract-android-tools/j
ni/../external/leptonlib-1.66/src/adaptmap.o'. Stop.
Please help me to sort out this problem.
I had the same issue and I think I solved it. May be helpful for those who get similar errors:
On OSX, I just changed the Android.mk files by giving the absolute paths as follows
First: jni/Android.mk
TESSERACT_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/external/tesseract-3.00
LEPTONICA_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/external/leptonlib-1.66
LIBJPEG_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/external/libjpeg
Then: jni/com_googlecode_leptonica_android/Android.mk
REAL_LOCAL_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/jni/com_googlecode_leptonica_android
and jni/com_googlecode_tesseract_android/Android.mk accordingly.
I believe the problem is caused by the relative path which is returned by the following command:
$(call my-dir)
Then I needed to run the ndk-build as superuser and all compiled just fine.
Search for adaptmap among the makefiles. Build the makefile that creates this module first.
So, I have compiled in windows 7 and windows xp, but it´s an ugly workaround.
The basic problem is "LOCAL_PATH := "with blank value, I don´t know why cygwin have problem with this, so you have to change paths on Android.mk files to work.
I will refer for Android.mk using numbers, my jni path is:
-jni
Android.mk(1)
Aplication.Mk
-com_googlecode_tesseract_android(dir)
Android.mk(2)
tesseract(dir)
-com_googlecode_leptonica_android(dir)
Android.mk(3)
leptonlib(dir)
-libjpeg
Android.mk(4)
=================================
Android.mk(1)
Put tesseract and leptonica sources on googlecode subdirectories like this:
TESSERACT_PATH := $(call my-dir)/com_googlecode_tesseract_android/tesseract -- directory to source, change for respective name
LEPTONICA_PATH := $(call my-dir)/com_googlecode_leptonica_android/leptonlib -- directory to source, change for respective name
LIBJPEG_PATH := $(call my-dir)/libjpeg
=================================
Android.mk(2)
1 - Change:
LOCAL_PATH:=
to
LOCAL_PATH:= $(call my-dir)
2 - Change:
BLACKLIST_SRC_FILES := \
%endiantest.c \
%freetype.c \
%xtractprotos.c
LOCAL_SRC_FILES := \
$(filter-out $(BLACKLIST_SRC_FILES),$(wildcard $(LEPTONICA_PATH)/src/*.c))
to
LOCAL_SRC_FILES := \
leptonlib/src/adaptmap.c \
leptonlib/src/affine.c \
leptonlib/src/affinecompose.c \ ... continue (Put all the files on src directory, without files listed on blacklist).
Note: replace leptonlib for subrectory name of leptonlib source.
3- Change:
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SRC_FILES += \
$(REAL_LOCAL_PATH)/stdio/open_memstream.c \
$(REAL_LOCAL_PATH)/stdio/fopencookie.c \
$(REAL_LOCAL_PATH)/stdio/fmemopen.c
LOCAL_C_INCLUDES += \
$(REAL_LOCAL_PATH)/stdio
endif
# jni
LOCAL_SRC_FILES += \
$(REAL_LOCAL_PATH)/box.cpp \
$(REAL_LOCAL_PATH)/pix.cpp \
$(REAL_LOCAL_PATH)/pixa.cpp \
$(REAL_LOCAL_PATH)/utilities.cpp \
$(REAL_LOCAL_PATH)/readfile.cpp \
$(REAL_LOCAL_PATH)/writefile.cpp \
$(REAL_LOCAL_PATH)/jni.cpp
LOCAL_C_INCLUDES += \
$(REAL_LOCAL_PATH) \
$(LEPTONICA_PATH)/src
to
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SRC_FILES += \
stdio/open_memstream.c \
stdio/fopencookie.c \
stdio/fmemopen.c
LOCAL_C_INCLUDES += \
stdio
endif
# jni
LOCAL_SRC_FILES += \
box.cpp \
pix.cpp \
pixa.cpp \
utilities.cpp \
jni.cpp
LOCAL_C_INCLUDES += \
leptonlib/src
=================================
Android.mk(3)
1 - Change:
LOCAL_PATH:=
to
LOCAL_PATH:= $(call my-dir)
2 - Change
On LOCAL_SRC_FILES change $(TESSERACT_PATH) to tesseract --Note: replace tesseract for subrectory name of tesseract source.
DON´T REPLACE $(TESSERACT_PATH) on LOCAL_C_INCLUDES only LOCAL_SRC_FILES.
DON´T REPLACE $(LEPTONICA_PATH) on LOCAL_C_INCLUDES.
3 - Change:
In #jni
LOCAL_SRC_FILES += \
$(REAL_LOCAL_PATH)/tessbaseapi.cpp
LOCAL_C_INCLUDES += \
$(REAL_LOCAL_PATH) \
$(TESSERACT_PATH)/api \
$(LEPTONICA_PATH)/src
to
LOCAL_SRC_FILES += \
tessbaseapi.cpp
LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
$(TESSERACT_PATH)/api \
$(LEPTONICA_PATH)/src
For me working on windows 7, windows xp, Mac and Ubuntu.