简体   繁体   中英

`ndk-build` treates `LOCAL_PATH` as a source file

I got the following error when I ran ndk-build :

[armeabi-v7a-hard] Executable     : simpleFlow
/opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: fatal error: jni/../jni/../: pread failed: Is a directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/armeabi-v7a/simpleFlow] Error 1

Turn on verbose flag, it seems that jni/../jni/../ (ie my LOCAL_PATH ) is mistakenly treated as a source file:

[armeabi-v7a-hard] Executable     : simpleFlow
Android clang version 3.8.275480  (based on LLVM 3.8.275480)
Target: armv7-none-linux-android
Thread model: posix
InstalledDir: /opt/android-ndk-r14b/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: /opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x
Selected GCC installation: /opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x
Candidate multilib: thumb;@thumb
Candidate multilib: armv7-a;@armv7
Candidate multilib: armv7-a/thumb;@armv7@thumb
Candidate multilib: .;
Selected multilib: armv7-a;@armv7
 "/opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld" --sysroot=/opt/android-ndk-r14b/platforms/android-9/arch-arm -pie -z relro -X --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /system/bin/linker -o ./obj/local/armeabi-v7a/simpleFlow /opt/android-ndk-r14b/platforms/android-9/arch-arm/usr/lib/../lib/crtbegin_dynamic.o -L/opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/armv7-a -L/opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a -L/opt/android-ndk-r14b/platforms/android-9/arch-arm/usr/lib/../lib -L/opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a -L/opt/android-ndk-r14b/platforms/android-9/arch-arm/usr/lib --gc-sections -z nocopyreloc -rpath-link=/opt/android-ndk-r14b/platforms/android-9/arch-arm/usr/lib -rpath-link=./obj/local/armeabi-v7a ./obj/local/armeabi-v7a/objs/simpleFlow/jni/__/jni/__/src/test.o jni/../jni/../ jni/../jni/../lib/libopenblas.a /opt/android-ndk-r14b/sources/cxx-stl/stlport/libs/armeabi-v7a/libstlport_static.a -lgcc --fix-cortex-a8 --no-warn-mismatch -lm_hard --build-id --no-undefined -z noexecstack -z relro -z now --warn-shared-textrel --fatal-warnings -lc -lm -lstdc++ -lm -lgcc -lgcc -ldl -lc -lgcc -lgcc -ldl /opt/android-ndk-r14b/platforms/android-9/arch-arm/usr/lib/../lib/crtend_android.o
/opt/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: fatal error: jni/../jni/../: pread failed: Is a directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/armeabi-v7a/simpleFlow] Error 1

Here's my jni/Android.mk :

LOCAL_PATH := $(call my-dir)/..

include $(CLEAR_VARS)

LOCAL_MODULE := openblas
LOCAL_SRC_FILES += $(LOCAL_PATH)/lib/libopenblas.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := simpleFlow
LOCAL_SRC_FILES += $(LOCAL_PATH)/src/test.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := openblas

LOCAL_CFLAGS := -pie -fPIE -O3 -ftree-vectorize -std=c++11 -mfloat-abi=hard -mhard-float -D_NDK_MATH_NO_SOFTFP=1 -v
LOCAL_LDFLAGS := -pie -fPIE -v -Wl,--no-warn-mismatch -lm_hard

TARGET_PLATFORM := android-20
TARGET_ARCH_ABI := armeabi-v7a-hard
APP_ABI := armeabi-v7a-hard

include $(BUILD_EXECUTABLE)

Here are the files under my project root path:

.
├── bin
├── include
│   ├── cblas.h
│   ├── f77blas.h
│   ├── lapacke_config.h
│   ├── lapacke.h
│   ├── lapacke_mangling.h
│   ├── lapacke_utils.h
│   └── openblas_config.h
├── jni
│   ├── Android.mk
│   ├── Application.mk
├── lib
│   ├── cmake
│   │   └── openblas
│   ├── libopenblas.a -> libopenblas_armv7p-r0.2.20.dev.a
│   ├── libopenblas_armv7p-r0.2.20.dev.a
│   └── pkgconfig
└── src
    └── test.cpp

I think there must be something wrong in the Android.mk . But after googling similar questions, I still haven't found an answer.


Edited:

Thanks to the suggestion of @mstorsjo, I have found a way to make it work: replacing LOCAL_SRC_FILES += $(LOCAL_PATH)/lib/libopenblas.a with LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/libopenblas.a . Is there any reasonable explaination?

BTW. I use $(warning $(LOCAL_SRC_FILES)) to check the variable LOCAL_SRC_FILES before and after the assignment, LOCAL_SRC_FILES += $(LOCAL_PATH)/lib/libopenblas.a and LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/libopenblas.a produce the same result.


Edited:

The LOCAL_SRC_FILES produced by LOCAL_SRC_FILES += $(LOCAL_PATH)/lib/libopenblas.a and LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/libopenblas.a are in fact different.

See the following picture (on the left: LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/libopenblas.a , on the right: LOCAL_SRC_FILES += $(LOCAL_PATH)/lib/libopenblas.a ):

左侧:<code> LOCAL_SRC_FILES:= $(LOCAL_PATH)/lib/libopenblas.a </ code>,右侧:<code> LOCAL_SRC_FILES + = $(LOCAL_PATH)/lib/libopenblas.a </ code>

Not sure if this is the actual issue you're having or not, but there's at least one oddity: The file names in LOCAL_SRC_FILES are implicitly relative to LOCAL_PATH , so you should remove that and make it simply LOCAL_SRC_FILES += lib/libopenblas.a (and similarly LOCAL_SRC_FILES += src/test.cpp ). Since LOCAL_PATH in your case is jni/.. , the extra duplication doesn't seem to hurt though.

Although I'm not sure if this will explain and fix your case of the extra jni/../jni/../ as a separate word which is the main issue you're facing, but it's at least worth a try.

You might also want to try doing the assignment using := instead of += if that also would help here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM