Android NDK Cmake linker * .so Нет такого файла или каталога - PullRequest
0 голосов
/ 17 сентября 2018

У меня очень простой проект, но при компиляции произошла ошибка, которую я не смог понять. linker command failed with exit code 1

Системная среда

 Windows 10 x64    
 Java 8    
 Gradle 4.5
 ------------------------------------    
 Build time:   2018-01-24 17:04:52 UTC
 Revision:     77d0ec90636f43669dc794ca17ef80dd65457bec
 Groovy:       2.4.12
 Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
 JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
 OS:           Windows 10 10.0 amd64
 NDK:          F:\Windows\android-sdk\ndk-bundle

Информация о конфигурации

build.gralde (root)

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}

build.gradle (приложение)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        externalNativeBuild {
            cmake {
                cppFlags '-std=gnu++11', '-fpermissive', '-v'
                arguments '-DANDROID_TOOLCHAIN=clang'
            }
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'x86'
        }
    }
}

CMakeList.txt

cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
find_library(log-lib log )
target_link_libraries(native-lib ${log-lib} )

native-lib.cpp

#include <jni.h>
#include <string>

extern "C"
JNIEXPORT jstring

JNICALL
Java_com_github_gam2046_ndktest_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

Сообщение об ошибке

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildJiangsuTelecomNormalIntegratedBrowserWithAnimationDebug'.
> Build command failed.
  Error while executing process F:\Windows\android-sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build E:\projects\UnitedPlatform\BasePlatform\app\.externalNativeBuild\cmake\JiangsuTelecomNormalIntegratedBrowserWithAnimationDebug\armeabi-v7a --target native-lib}
  [1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
  Android (4691093 based on r316199) clang version 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55536e7d904e0abae47888fc7f) (https://android.googlesource.com/toolchain/llvm 34361f192e41ed6e4e8f9aca80a4ea7e9856f327) (based on LLVM 6.0.2svn)
  Target: armv7-none-linux-android
  Thread model: posix
  InstalledDir: F:\Windows\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin
  Found candidate GCC installation: F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi\4.9.x
  Selected GCC installation: F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x
  Candidate multilib: thumb;@mthumb
  Candidate multilib: armv7-a;@march=armv7-a
  Candidate multilib: armv7-a/thumb;@march=armv7-a@mthumb
  Candidate multilib: .;
  Selected multilib: armv7-a/thumb;@march=armv7-a@mthumb
   "F:\\Windows\\android-sdk\\ndk-bundle\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\clang++.exe" -cc1 -triple thumbv7-none-linux-android -emit-obj -mrelax-all -mnoexecstack -disable-free -disable-llvm-verifier -discard-value-names -main-file-name native-lib.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu generic -target-feature +soft-float-abi -target-feature -fp-only-sp -target-feature +d16 -target-feature +vfp3 -target-feature -fp16 -target-feature -vfp4 -target-feature -fp-armv8 -target-feature -neon -target-feature -crypto -target-abi aapcs-linux -mfloat-abi soft -fallow-half-arguments-and-returns -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -v -ffunction-sections -coverage-notes-file "E:\\projects\\UnitedPlatform\\BasePlatform\\app\\.externalNativeBuild\\cmake\\JiangsuTelecomNormalIntegratedBrowserWithAnimationDebug\\armeabi-v7a\\CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.gcno" -resource-dir "F:\\Windows\\android-sdk\\ndk-bundle\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\6.0.2" -dependency-file "CMakeFiles\\native-lib.dir\\src\\main\\cpp\\native-lib.cpp.o.d" -sys-header-deps -MT CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -isystem F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include -isystem F:/Windows/android-sdk/ndk-bundle/sources/android/support/include -isystem F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include -isystem F:/Windows/android-sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D native_lib_EXPORTS -D __ANDROID_API__=19 -D ANDROID -isysroot F:/Windows/android-sdk/ndk-bundle/sysroot -internal-isystem F:/Windows/android-sdk/ndk-bundle/sysroot/usr/local/include -internal-isystem "F:\\Windows\\android-sdk\\ndk-bundle\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\6.0.2\\include" -internal-externc-isystem F:/Windows/android-sdk/ndk-bundle/sysroot/include -internal-externc-isystem F:/Windows/android-sdk/ndk-bundle/sysroot/usr/include -O0 -Wformat -Werror=format-security -std=gnu++11 -fdeprecated-macro -fdebug-compilation-dir "E:\\projects\\UnitedPlatform\\BasePlatform\\app\\.externalNativeBuild\\cmake\\JiangsuTelecomNormalIntegratedBrowserWithAnimationDebug\\armeabi-v7a" -ferror-limit 19 -fmessage-length 0 -femulated-tls -stack-protector 2 -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -x c++ "E:\\projects\\UnitedPlatform\\BasePlatform\\app\\src\\main\\cpp\\native-lib.cpp"
  clang -cc1 version 6.0.2 based upon LLVM 6.0.2svn default target x86_64-w64-windows-gnu
  ignoring nonexistent directory "F:/Windows/android-sdk/ndk-bundle/sysroot/usr/local/include"
  ignoring nonexistent directory "F:/Windows/android-sdk/ndk-bundle/sysroot/include"
  #include "..." search starts here:
  #include <...> search starts here:
   F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include
   F:/Windows/android-sdk/ndk-bundle/sources/android/support/include
   F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include
   F:/Windows/android-sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
   F:\Windows\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\6.0.2\include
   F:/Windows/android-sdk/ndk-bundle/sysroot/usr/include
  End of search list.
  [2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\JiangsuTelecomNormalIntegratedBrowserWithAnimation\debug\obj\armeabi-v7a\libnative-lib.so
  FAILED: cmd.exe /C "cd . && F:\Windows\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=armv7-none-linux-androideabi --gcc-toolchain=F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=F:/Windows/android-sdk/ndk-bundle/sysroot -fPIC -isystem F:/Windows/android-sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=19 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=gnu++11 -fpermissive -v -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot F:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -LF:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\JiangsuTelecomNormalIntegratedBrowserWithAnimation\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  -llog -latomic -lm "F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libandroid_support.a" "F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl" && cd ."
  Android (4691093 based on r316199) clang version 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55536e7d904e0abae47888fc7f) (https://android.googlesource.com/toolchain/llvm 34361f192e41ed6e4e8f9aca80a4ea7e9856f327) (based on LLVM 6.0.2svn)
  Target: armv7-none-linux-android
  Thread model: posix
  InstalledDir: F:\Windows\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin
  Found candidate GCC installation: F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi\4.9.x
  Selected GCC installation: F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x
  Candidate multilib: thumb;@mthumb
  Candidate multilib: armv7-a;@march=armv7-a
  Candidate multilib: armv7-a/thumb;@march=armv7-a@mthumb
  Candidate multilib: .;
  Selected multilib: armv7-a/thumb;@march=armv7-a@mthumb
   "F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\\ld" --sysroot=F:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm -X --eh-frame-hdr -m armelf_linux_eabi -shared -o "..\\..\\..\\..\\build\\intermediates\\cmake\\JiangsuTelecomNormalIntegratedBrowserWithAnimation\\debug\\obj\\armeabi-v7a\\libnative-lib.so" "F:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm/usr/lib/../lib\\crtbegin_so.o" -LF:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a "-LF:\\Windows\\android-sdk\\ndk-bundle\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\6.0.2\\lib\\linux\\arm" -LF:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb -LF:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a/thumb -LF:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm/usr/lib/../lib -LF:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm/usr/lib/arm-linux-androideabi/../../lib -LF:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb -LF:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm/usr/lib --exclude-libs libgcc.a --exclude-libs libatomic.a --build-id --warn-shared-textrel --fatal-warnings --fix-cortex-a8 --exclude-libs libunwind.a --no-undefined -z noexecstack -z relro -z now -soname libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -latomic -lm F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libandroid_support.a F:/Windows/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a -ldl -lm -lgcc -ldl -lc -lgcc -ldl "F:/Windows/android-sdk/ndk-bundle/platforms/android-19/arch-arm/usr/lib/../lib\\crtend_so.o"
  F:/Windows/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: fatal error: ..\..\..\..\build\intermediates\cmake\JiangsuTelecomNormalIntegratedBrowserWithAnimation\debug\obj\armeabi-v7a\libnative-lib.so: open: No such file or directory
  clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

Некоторые удивительные вещи

Тот же код, система и окружение, git clone для другого локального расположения, могут быть скомпилированы нормально.Но git diff не показывает никакой разницы.

Еще более удивительным образом, если я скопирую код в другое локальное местоположение (например, с диска D на диск E), он будет скомпилирован нормально.Я проверил, что на диске много свободного места.Если вы переименуете каталог в его исходное местоположение, компиляция все равно не удастся.

Аналогичным образом я попытался уничтожить все процессы java.exe.Перезагрузите компьютер и т. Д. Ситуация остается прежней.

Я не могу понять, почему один и тот же код вызовет сбой компиляции на разных дисках.Согласно информации, предоставленной компилятором, он связан с целевым файлом, но больше нет действительной информации.Я также попытался скомпилировать этот код в Linux без проблем

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...