#include <string> fails when using Crystax NDK 10.3.1

166 views
Skip to first unread message

scott....@gmail.com

unread,
May 13, 2016, 1:10:01 AM5/13/16
to crystax-ndk
Hello.

I get build errors, #include <string> can't find the file (I assume many other include files would also not be found, for example I know <queue> is also not found). 

I'm using this setup:

OSX
Crystax NDK 10.3.1
Android Studio 2.1.1
Experimental plug 0.7.0
toolchain clang 3.7
stl c++_shared

If I switch the stl to be "gnustl_shared" then <string> is found (app will build completely, and run as expected)

Any ideas on what might be going on?

Thanks!

/scott


Dmitry Moskalchuk

unread,
May 13, 2016, 1:30:20 AM5/13/16
to cryst...@googlegroups.com

Hello,

This happens because gradle plugin looks for c++_shared in the folder $NDK/sources/cxx-stl/llvm-libc++ (where it is in Google's Android NDK), but in CrystaX NDK it resides in $NDK/sources/cxx-stl/llvm-libc++/$LLVM_VERSION.

You can fix it either by manually copying content of $NDK/sources/cxx-stl/llvm-libc++/3.7/ folder to the $NDK/sources/cxx-stl/llvm-libc++ (quick and dirty fix) or by specifying all paths to C++ headers and libraries manually in your gradle script - the same as it's done for Boost libraries in https://github.com/crystax/android-samples-android-studio/blob/master/app/build.gradle.

Something like this:


def getLibCxxDir() {
    return "${getCrystaxNdkDir()}/sources/cxx-stl/llvm-libc++/3.7"
}

def getLibCxxAbiDir() {
    return "${getCrystaxNdkDir()}/sources/cxx-stl/llvm-libc++abi"
}

def getLibCxxIncDir() {
    return "${getLibCxxDir()}/libcxx/include"
}

def getLibCxxLibDir(abi) {
    return "${getLibCxxDir()}/libs/${abi}"
}

def getLibCxxAbiIncDir() {
    return "${getLibCxxAbiDir()}/libcxxabi/include"
}

..........

    android.ndk {
        ...........
        cppFlags += "-I" + getLibCxxIncDir()
        cppFlags += "-I" + getLibCxxAbiIncDir()
        ldLibs += "c++_shared"
        ...........
    }

..........

task copyNativeLibs {
    .........
    def libs = [:]
    .........
    libs['c++_shared'] = "${getLibCxxLibDir(abi)}/libc++_shared.so"
    .........
    libs.each { name, file ->
        dependsOn tasks.create(name: "copy-native-libs-${name}-${abi}-${buildType}", type: Copy) {
            from file
            into getTargetLibDir(abi, buildType)
        }
    }
    .........
}


-- 
Dmitry Moskalchuk
--
You received this message because you are subscribed to the Google Groups "crystax-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystax-ndk...@googlegroups.com.
To post to this group, send email to cryst...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystax-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystax-ndk/2a1494d1-a491-4e3d-a683-2f3ee708cd33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

scott....@gmail.com

unread,
May 13, 2016, 3:02:15 PM5/13/16
to crystax-ndk
Thanks for the info and quick response, Dmitry.

I've added your suggestions, but now I have a different build issue, I get errors like this:

crystax-ndk-10.3.1/sources/cxx-stl/llvm-libc++/3.7/libcxx/include/type_traits:325:49: error: use of undeclared identifier 'nullptr_t'; did you mean 'nullptr'?
template <>          struct __is_nullptr_t_impl<nullptr_t> : public true_type {};

pretty strange to see the compiler not know what nullptr_t is? so there must be something I'm missing...

any ideas? (for reference, all this code - which is a 3rd party sdk - used to compile just fine w/ the Android NDK using clang and c++_shared...)

Dmitry Moskalchuk

unread,
May 13, 2016, 3:19:03 PM5/13/16
to cryst...@googlegroups.com

It seems like you haven't included <cstddef> before that header.

The fact that code compiles with Google's Android NDK should not confuse - main goal of CrystaX NDK is conformance to standards, thus many things are just more strict than in Google's NDK. For example, using Google's NDK, you may implicitly include <cstddef> by including other header, but in CrystaX NDK it's not included implicitly so it has to be included explicitly.

However, I can't say for sure what's wrong without having specific code. All above is just an assumption. It would be good if you could provide some minimal example, where this error is reproduced.

-- 
Dmitry Moskalchuk
--
You received this message because you are subscribed to the Google Groups "crystax-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystax-ndk...@googlegroups.com.
To post to this group, send email to cryst...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystax-ndk.

scott....@gmail.com

unread,
May 13, 2016, 6:44:21 PM5/13/16
to crystax-ndk
I did some more digging.

it looks like include paths for the other cxx-stl folders are, for some reason, being included in the search path for include files, so we sometimes end up including something from say gnu-libstdc++ instead of just looking in the llvm path.

when I move these folders [gabi++, gnu-libstdc++, stlport, system] into a subfolder named "unused", then some of the builds work (I have 4 projects in total being built).

eventually, one of the builds will fail linking, it's looking for the c++_shared.so in a path like $NDK/sources/cxx-stl/llvm-libc++/$LLVM_VERSION
(notice that it's missing the "3.7" bit)

So i reverted most of my gradle changes, and just did the quicker "hack" of moving the 3.7 folder up one level, and it works.

maybe this is due to the experimental plugin being used (0.7.0)? perhaps there are some places where it's not correctly dealing with having multiple clang versions etc.?

I wonder if it might be easier to always try and mirror the NDK layout exactly, rather than supporting multiple versions of clang, etc... and I hear gcc is deprecated now too?

thanks again for the quick response! 
/scott

Dmitry Moskalchuk

unread,
May 14, 2016, 1:38:13 PM5/14/16
to cryst...@googlegroups.com

Yes, gradle plugin doesn't handle several versions of LLVM libc++. It just looks in hard-coded path.

It seems that we are forced to keep the same structure for one (default) LLVM libc++ version, just to make Android Studio and Visual Studio happy, even though it looks ugly. So yes, in the next release LLVM libc++ layout will be fixed in order to reflect that.


-- 
Dmitry Moskalchuk

Declan

unread,
Jan 17, 2017, 4:23:49 AM1/17/17
to crystax-ndk
Hello,

I also have this problem but I cant confirm that using this "quick and dirty" fix works.

I have the current version (2.2.3) of android studio, and the crystax nightly build from dec 9 2016.

If I take say the google sample:
 https://github.com/googlesamples/android-ndk/tree/gradle-experimental/hello-libs

I can get it to work fine if I "drop in" crystax instead of google's ndk, with

ndk {
stl
"gnustl_shared"
...


I can also get it to work fine if I use
stl "c++_shared"

and googles ndk.

However, if I use both crystax and c++_shared, then the first problem is a link error:
"ld: error: cannot find -lc++_shared"

 This can be solved by creating a link:

cd /home/declan/Documents/zone/mid/bin/android/crystax/crystax-ndk-10.3.2_dec9/sources/cxx-stl/llvm-libc++
ln
-s ./3.8/libs ./libs    # solves  "ld: error: cannot find -lc++_shared"

Aftre this the problem is that the standard headers eg vector, if you include one eg

#include <vector>

This unfortunately cannot be solved by simple linking to or copying the crystax sub dir:

ln -s ./3.8/libcxx/include ./include        # does -NOT- solve "fatal error: 'vector' file not found     #include <vector>"

So the problem seems to be deeper.

Any ideas what still is amiss?






android
......
      abis{
            MY_ABIS.each { abi ->
                create(abi) {
                    ldFlags.add("-L${crystax_lib_dir(abi)}".toString())   // somehow need this but no others !! ??
Reply all
Reply to author
Forward
0 new messages