Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With NDK 13b, C++ cannot find <...> headers #255

Closed
JessHolle opened this issue Dec 7, 2016 · 23 comments
Closed

With NDK 13b, C++ cannot find <...> headers #255

JessHolle opened this issue Dec 7, 2016 · 23 comments

Comments

@JessHolle
Copy link

With NDK 13b, Android Studio 2.2.x (at least 2.2.2 and 2.2.3 and using the experimental NDK plugin) can no longer follow includes of , , , etc.

I am filing this as an NDK bug as all previous NDK versions worked just fine with various Android Studio versions.

I am currently stuck at NDK 12b awaiting some resolution of this issue.

build.gradle excerpt:
build.gradle.snippet.txt

@JessHolle
Copy link
Author

JessHolle commented Dec 7, 2016 via email

@victorv
Copy link

victorv commented Dec 7, 2016

can you compile using cppFlags.add("-v") and/or CFlags.add('-v') to see your compiler command options?

c++_shared works for us in our dlib implementation which uses the same headers/functions which are not found in your build.

@victorv
Copy link

victorv commented Dec 7, 2016

android.ndk {
    moduleName = "dlib_native"
    toolchain "clang"
    debuggable = true
    ldLibs.addAll(['dl', 'log', 'android', 'm', 'z', 'opencv_java3', 'c++_shared'])
    ldFlags.add("-L" + file("../opencv/src/main/jnilibs/arm64-v8a"))
    ldFlags.add("-L" + file("../opencv/src/main/jnilibs/armeabi-v7a"))
    ldFlags.add("--verbose")
    abiFilters.addAll(['armeabi-v7a', 'arm64-v8a'])
    CFlags.add("-v")
    cppFlags.add("-v")
    cppFlags.add("-DDLIB_NO_GUI_SUPPORT")
    cppFlags.add("-I" + file("src/main/jni").absolutePath)
    cppFlags.add("-I" + file("./").absolutePath)
    cppFlags.add("-I" + file("../opencv/src/main/jni/include").absolutePath)
    cppFlags.addAll(["-frtti","-fexceptions","-std=c++11"])
    cppFlags.addAll(["-O3"])
    stl = "c++_shared"
}

Our android.ndk section which works

@JessHolle
Copy link
Author

Verbose output attached.
output.txt

@victorv
Copy link

victorv commented Dec 8, 2016

LLVM-c++ which is what c++_shared is based on is known to be incomplete for r13 (see #82)

how about listing all the files here on your machine here D:\Users\jessh\AppData\Local\Android\sdk1\ndk-bundle\sources\cxx-stl\llvm-libc++\libcxx\include ?

If the files aren't there, they are probably not included in the c++_shared. But I know we use some of the includes which are missing for you so there is something else going on.

@JessHolle
Copy link
Author

JessHolle commented Dec 8, 2016 via email

@victorv
Copy link

victorv commented Dec 8, 2016

These are my entries in r13b / sources / cxx-stl :
drwxr-xr-x@ 9 xxx staff 306 Oct 12 15:40 gabi++
drwxr-xr-x@ 4 xxx staff 136 Oct 12 15:52 gnu-libstdc++
drwxr-xr-x@ 28 xxx staff 952 Oct 12 15:41 llvm-libc++
drwxr-xr-x@ 19 xxx staff 646 Oct 12 15:40 llvm-libc++abi
drwxr-xr-x@ 15 xxx staff 510 Oct 12 15:44 stlport
drwxr-xr-x@ 8 xxx staff 272 Oct 12 15:40 system

And in llvm-libc++ (edited for brevity):
drwxr-xr-x@ 122 xxx staff 4148 Oct 12 15:40 include
drwxr-xr-x@ 10 xxx staff 340 Oct 12 15:40 lib
drwxr-xr-x@ 9 xxx staff 306 Oct 12 15:41 libs
drwxr-xr-x@ 32 xxx staff 1088 Oct 12 15:40 src
drwxr-xr-x@ 5 xxx staff 170 Oct 12 15:40 utils
drwxr-xr-x@ 18 xxx staff 612 Oct 12 15:40 www

and in include :
-rw-r--r--@ 1 xxx staff 52514 Oct 12 15:40 __bit_reference
-rw-r--r--@ 1 xxx staff 2008 Oct 12 15:40 __bsd_locale_defaults.h
-rw-r--r--@ 1 xxx staff 4247 Oct 12 15:40 __bsd_locale_fallbacks.h
-rw-r--r--@ 1 xxx staff 24652 Oct 12 15:40 __config
-rw-r--r--@ 1 xxx staff 828 Oct 12 15:40 __config_site.in
-rw-r--r--@ 1 xxx staff 5898 Oct 12 15:40 __debug
-rw-r--r--@ 1 xxx staff 44111 Oct 12 15:40 __functional_03
-rw-r--r--@ 1 xxx staff 18292 Oct 12 15:40 __functional_base
-rw-r--r--@ 1 xxx staff 6519 Oct 12 15:40 __functional_base_03
-rw-r--r--@ 1 xxx staff 92405 Oct 12 15:40 __hash_table
-rw-r--r--@ 1 xxx staff 45586 Oct 12 15:40 __locale
-rw-r--r--@ 1 xxx staff 12424 Oct 12 15:40 __mutex_base
-rw-r--r--@ 1 xxx staff 2106 Oct 12 15:40 __nullptr
-rw-r--r--@ 1 xxx staff 3412 Oct 12 15:40 __refstring
-rw-r--r--@ 1 xxx staff 22242 Oct 12 15:40 __split_buffer
-rw-r--r--@ 1 xxx staff 2491 Oct 12 15:40 __sso_allocator
-rw-r--r--@ 1 xxx staff 10503 Oct 12 15:40 __std_stream
-rw-r--r--@ 1 xxx staff 4647 Oct 12 15:40 __threading_support
-rw-r--r--@ 1 xxx staff 94288 Oct 12 15:40 __tree
-rw-r--r--@ 1 xxx staff 12053 Oct 12 15:40 __tuple
-rw-r--r--@ 1 xxx staff 648 Oct 12 15:40 __undef___deallocate
-rw-r--r--@ 1 xxx staff 945 Oct 12 15:40 __undef_min_max
-rw-r--r--@ 1 xxx staff 200798 Oct 12 15:40 algorithm
-rw-r--r--@ 1 xxx staff 11609 Oct 12 15:40 array
-rw-r--r--@ 1 xxx staff 61016 Oct 12 15:40 atomic
-rw-r--r--@ 1 xxx staff 34032 Oct 12 15:40 bitset
-rw-r--r--@ 1 xxx staff 546 Oct 12 15:40 cassert
-rw-r--r--@ 1 xxx staff 627 Oct 12 15:40 ccomplex
-rw-r--r--@ 1 xxx staff 1745 Oct 12 15:40 cctype
-rw-r--r--@ 1 xxx staff 656 Oct 12 15:40 cerrno
-rw-r--r--@ 1 xxx staff 1588 Oct 12 15:40 cfenv
-rw-r--r--@ 1 xxx staff 1134 Oct 12 15:40 cfloat
-rw-r--r--@ 1 xxx staff 40811 Oct 12 15:40 chrono
-rw-r--r--@ 1 xxx staff 3490 Oct 12 15:40 cinttypes
-rw-r--r--@ 1 xxx staff 582 Oct 12 15:40 ciso646
-rw-r--r--@ 1 xxx staff 894 Oct 12 15:40 climits
-rw-r--r--@ 1 xxx staff 985 Oct 12 15:40 clocale
-rw-r--r--@ 1 xxx staff 13549 Oct 12 15:40 cmath
-rw-r--r--@ 1 xxx staff 20446 Oct 12 15:40 codecvt
-rw-r--r--@ 1 xxx staff 45061 Oct 12 15:40 complex
-rw-r--r--@ 1 xxx staff 726 Oct 12 15:40 complex.h
-rw-r--r--@ 1 xxx staff 7475 Oct 12 15:40 condition_variable
-rw-r--r--@ 1 xxx staff 800 Oct 12 15:40 csetjmp
-rw-r--r--@ 1 xxx staff 951 Oct 12 15:40 csignal
-rw-r--r--@ 1 xxx staff 890 Oct 12 15:40 cstdarg
-rw-r--r--@ 1 xxx staff 708 Oct 12 15:40 cstdbool
-rw-r--r--@ 1 xxx staff 1146 Oct 12 15:40 cstddef
-rw-r--r--@ 1 xxx staff 2785 Oct 12 15:40 cstdint
-rw-r--r--@ 1 xxx staff 4321 Oct 12 15:40 cstdio
-rw-r--r--@ 1 xxx staff 4611 Oct 12 15:40 cstdlib
-rw-r--r--@ 1 xxx staff 2526 Oct 12 15:40 cstring
-rw-r--r--@ 1 xxx staff 637 Oct 12 15:40 ctgmath
-rw-r--r--@ 1 xxx staff 1413 Oct 12 15:40 ctime
-rw-r--r--@ 1 xxx staff 1420 Oct 12 15:40 ctype.h
-rw-r--r--@ 1 xxx staff 6416 Oct 12 15:40 cwchar
-rw-r--r--@ 1 xxx staff 1678 Oct 12 15:40 cwctype
-rw-r--r--@ 1 xxx staff 104664 Oct 12 15:40 deque
-rw-r--r--@ 1 xxx staff 5131 Oct 12 15:40 errno.h
-rw-r--r--@ 1 xxx staff 8050 Oct 12 15:40 exception
drwxr-xr-x@ 28 xxx staff 952 Oct 12 15:40 experimental
drwxr-xr-x@ 5 xxx staff 170 Oct 12 15:40 ext
-rw-r--r--@ 1 xxx staff 1327 Oct 12 15:40 float.h
-rw-r--r--@ 1 xxx staff 59886 Oct 12 15:40 forward_list
-rw-r--r--@ 1 xxx staff 44957 Oct 12 15:40 fstream
-rw-r--r--@ 1 xxx staff 77388 Oct 12 15:40 functional
-rw-r--r--@ 1 xxx staff 71181 Oct 12 15:40 future
-rw-r--r--@ 1 xxx staff 2846 Oct 12 15:40 initializer_list
-rw-r--r--@ 1 xxx staff 3371 Oct 12 15:40 inttypes.h
-rw-r--r--@ 1 xxx staff 17568 Oct 12 15:40 iomanip
-rw-r--r--@ 1 xxx staff 25099 Oct 12 15:40 ios
-rw-r--r--@ 1 xxx staff 7891 Oct 12 15:40 iosfwd
-rw-r--r--@ 1 xxx staff 1378 Oct 12 15:40 iostream
-rw-r--r--@ 1 xxx staff 50293 Oct 12 15:40 istream
-rw-r--r--@ 1 xxx staff 55382 Oct 12 15:40 iterator
-rw-r--r--@ 1 xxx staff 40511 Oct 12 15:40 limits
-rw-r--r--@ 1 xxx staff 77548 Oct 12 15:40 list
-rw-r--r--@ 1 xxx staff 147913 Oct 12 15:40 locale
-rw-r--r--@ 1 xxx staff 72862 Oct 12 15:40 map
-rw-r--r--@ 1 xxx staff 45701 Oct 12 15:40 math.h
-rw-r--r--@ 1 xxx staff 180586 Oct 12 15:40 memory
-rw-r--r--@ 1 xxx staff 12732 Oct 12 15:40 module.modulemap
-rw-r--r--@ 1 xxx staff 14132 Oct 12 15:40 mutex
-rw-r--r--@ 1 xxx staff 5795 Oct 12 15:40 new
-rw-r--r--@ 1 xxx staff 6407 Oct 12 15:40 numeric
-rw-r--r--@ 1 xxx staff 32784 Oct 12 15:40 ostream
-rw-r--r--@ 1 xxx staff 25448 Oct 12 15:40 queue
-rw-r--r--@ 1 xxx staff 225708 Oct 12 15:40 random
-rw-r--r--@ 1 xxx staff 16387 Oct 12 15:40 ratio
-rw-r--r--@ 1 xxx staff 217941 Oct 12 15:40 regex
-rw-r--r--@ 1 xxx staff 22548 Oct 12 15:40 scoped_allocator
-rw-r--r--@ 1 xxx staff 46113 Oct 12 15:40 set
-rw-r--r--@ 1 xxx staff 789 Oct 12 15:40 setjmp.h
-rw-r--r--@ 1 xxx staff 14352 Oct 12 15:40 shared_mutex
-rw-r--r--@ 1 xxx staff 33219 Oct 12 15:40 sstream
-rw-r--r--@ 1 xxx staff 9368 Oct 12 15:40 stack
-rw-r--r--@ 1 xxx staff 802 Oct 12 15:40 stdbool.h
-rw-r--r--@ 1 xxx staff 1256 Oct 12 15:40 stddef.h
-rw-r--r--@ 1 xxx staff 4515 Oct 12 15:40 stdexcept
-rw-r--r--@ 1 xxx staff 3608 Oct 12 15:40 stdio.h
-rw-r--r--@ 1 xxx staff 4487 Oct 12 15:40 stdlib.h
-rw-r--r--@ 1 xxx staff 16056 Oct 12 15:40 streambuf
-rw-r--r--@ 1 xxx staff 157112 Oct 12 15:40 string
-rw-r--r--@ 1 xxx staff 4661 Oct 12 15:40 string.h
-rw-r--r--@ 1 xxx staff 11272 Oct 12 15:40 strstream
drwxr-xr-x@ 9 xxx staff 306 Oct 12 15:40 support
-rw-r--r--@ 1 xxx staff 21646 Oct 12 15:40 system_error
-rw-r--r--@ 1 xxx staff 645 Oct 12 15:40 tgmath.h
-rw-r--r--@ 1 xxx staff 13182 Oct 12 15:40 thread
-rw-r--r--@ 1 xxx staff 51927 Oct 12 15:40 tuple
-rw-r--r--@ 1 xxx staff 156848 Oct 12 15:40 type_traits
-rw-r--r--@ 1 xxx staff 2821 Oct 12 15:40 typeindex
-rw-r--r--@ 1 xxx staff 4351 Oct 12 15:40 typeinfo
-rw-r--r--@ 1 xxx staff 80902 Oct 12 15:40 unordered_map
-rw-r--r--@ 1 xxx staff 55380 Oct 12 15:40 unordered_set
-rw-r--r--@ 1 xxx staff 26925 Oct 12 15:40 utility
-rw-r--r--@ 1 xxx staff 134230 Oct 12 15:40 valarray
-rw-r--r--@ 1 xxx staff 109083 Oct 12 15:40 vector
-rw-r--r--@ 1 xxx staff 8080 Oct 12 15:40 wchar.h
-rw-r--r--@ 1 xxx staff 1541 Oct 12 15:40 wctype.h

@victorv
Copy link

victorv commented Dec 8, 2016

Maybe you need to "find . -name build | xargs rm -rf" to remove all build directories then run File -> Invalidate Caches and Restart

It is possible Android Studio has cached your old paths. Or your path is different under Windoz.

@victorv
Copy link

victorv commented Dec 8, 2016

From my DLIB compile :

compiling image_io.cpp successful.
Android clang version 3.8.256229 (based on LLVM 3.8.256229)
Target: aarch64-none-linux-android
Thread model: posix
InstalledDir: /Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin
Found candidate GCC installation: /Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x
Selected GCC installation: /Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++" -cc1 -triple aarch64-none-linux-android -emit-obj -disable-free -disable-llvm-verifier -main-file-name image_io.cpp -mrelocation-model pic -pic-level 1 -mthread-model posix -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu generic -target-feature +neon -target-abi aapcs -backend-option -aarch64-fix-cortex-a53-835769=1 -target-linker-version 2.24 -v -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -ffunction-sections -coverage-file /Users/xxx/10imaging/yyy/dlib/build/intermediates/objectFiles/dlib_nativeArm64-v8aDebugSharedLibraryMainCpp/4xy21xonbyblpd2x3tbng3zl3/image_io.o -resource-dir /Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/../lib64/clang/3.8.256229 -D ANDROID -D ANDROID_NDK -I /Users/xxx/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include -I /Users/xxx/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include -I /Users/xxx/Library/Android/sdk/ndk-bundle/sources/cxx-stl/../android/support/include -D NDEBUG -U NDEBUG -D DLIB_NO_GUI_SUPPORT -I /Users/xxx/10imaging/yyy/dlib/src/main/jni -I /Users/xxx/10imaging/yyy/dlib -I /Users/xxx/10imaging/yyy/opencv/src/main/jni/include -I /Users/xxx/10imaging/yyy/dlib/src/main/headers -isysroot /Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64 -internal-isystem /Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/usr/local/include -internal-isystem /Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/../lib64/clang/3.8.256229/include -internal-externc-isystem /Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/include -internal-externc-isystem /Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/usr/include -O3 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/xxx/10imaging/yyy/dlib/build/intermediates/objectFiles/dlib_nativeArm64-v8aDebugSharedLibraryMainCpp -ferror-limit 19 -fmessage-length 0 -femulated-tls -stack-protector 1 -fallow-half-arguments-and-returns -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o /Users/xxx/10imaging/yyy/dlib/build/intermediates/objectFiles/dlib_nativeArm64-v8aDebugSharedLibraryMainCpp/4xy21xonbyblpd2x3tbng3zl3/image_io.o -x c++ /Users/xxx/10imaging/yyy/dlib/src/main/jni/image_io.cpp
clang -cc1 version 3.8.256229 based upon LLVM 3.8.256229 default target x86_64-unknown-linux
ignoring nonexisxxxt directory "/Users/xxx/10imaging/yyy/dlib/src/main/headers"
ignoring nonexisxxxt directory "/Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/usr/local/include"
ignoring nonexisxxxt directory "/Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/include"
#include "..." search starts here:
#include <...> search starts here:
/Users/xxx/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include
/Users/xxx/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include
/Users/xxx/Library/Android/sdk/ndk-bundle/sources/cxx-stl/../android/support/include
/Users/xxx/10imaging/yyy/dlib/src/main/jni
/Users/xxx/10imaging/yyy/dlib
/Users/xxx/10imaging/yyy/opencv/src/main/jni/include
/Users/xxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/../lib64/clang/3.8.256229/include
/Users/xxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/usr/include
End of search list.

@JessHolle
Copy link
Author

I exited Android Studio, removed the .idea, .gradle, and build directories, re-imported the project into Android Studio, and the problem persists. I also tried Invalidate Caches and Restart -- so this is not a stale cache problem or at least not one I can do anything about.

@victorv
Copy link

victorv commented Dec 8, 2016

You could try removing your D:\Users\jessh\AppData\Local\Android\sdk1 and completely reloading the SDK and NDK. The problem seems to be the wrong include path. Have you tried hard-coding the -I path to cxx_shared includes ?

@JessHolle
Copy link
Author

JessHolle commented Dec 8, 2016 via email

@victorv
Copy link

victorv commented Dec 9, 2016

It's a hack to figure out if something else is wrong - to see if it can work. It is likely your SDK / NDK bundle is mangled in some way as it should not generate bogus -I paths.

@victorv
Copy link

victorv commented Dec 9, 2016

I build our library on OSX 10.10 and Ubuntu 14.04 and 16.04 - no windows around here.

@JessHolle
Copy link
Author

JessHolle commented Dec 9, 2016 via email

@victorv
Copy link

victorv commented Dec 9, 2016

What about a completely clean SDK and NDK install? If that doesn't work, I will dust-off an old windows 7 machine to try our build.

@JessHolle
Copy link
Author

JessHolle commented Dec 9, 2016 via email

@victorv
Copy link

victorv commented Dec 9, 2016

move your old SDK from D:\Users\jessh\AppData\Local\Android somewhere temporarily. Launch Android Studio or the SDK Manager and re-download / install all the items you need.

@JessHolle
Copy link
Author

I tried again with a clean SDK and NDK and got the same basic result.
output.txt

@DanAlbert
Copy link
Member

Apologies for not responding sooner, I've been on out for most of the week. Thanks a lot to @victorv for helping out :)

The core of the issue here (not finding libc++ headers) because they've (as you've noticed) moved from llvm-libc++/libcxx/include to llvm-libc++/include. The gradle plugin needed to be updated to handle that, but the update to do so was released months ago (back in the r13 beta 2 time frame, which was in mid September). Are you still using some older version of the gradle plugin, perhaps because you have an old version of Studio?

@victorv
Copy link

victorv commented Dec 9, 2016

Still looking in ndk-bundle\sources\cxx-stl\llvm-libc++\libcxx\include - maybe as @DanAlbert suggests you are running and old Android Studio, gradle plugin, etc.. We are using AS 2.2.2 and

    classpath 'com.android.tools.build:gradle-experimental:0.8.2'
    classpath 'com.android.tools.build:gradle:2.2.2'

@JessHolle
Copy link
Author

I had been using classpath 'com.android.tools.build:gradle-experimental:0.7.0'.

This appears to have been the problem. When re-importing the project, Android Studio suggested that I upgrade, but I had been in the habit of ignoring/negating this suggestion as it had caused issues in the past. At this point, however, it seems to work fine and solve the issue!

@victorv
Copy link

victorv commented Dec 9, 2016

yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants