Summary of NDK compile-time problems

When ndk compiles C++, it prompts that the header file cannot be found (ndk-build error: string: No such file or directory)
in the directory project /jni/Application.mk (that is, the same level as Android.mk)
------- ---cut start--------------------------------------------
# Standard library
APP_STL := gnustl_static--------- --cut end---------------------
Add APP_STL := gnustl_static
to find the standard library jni

in the project directory The c/c++ code written in the folder usually encounters the following types of errors when compiling:

1. Unresolved inclusion: <XXX>

2. syntax error

3. Function 'XXX' could not be resolved

4. Type ' XXX' could not be resolved

5, Symbol 'XXX' could not be resolved

6, Method 'XXX' could not be resolved

7, Invalid arguments 'Candidates are: ...'


Error reason:

Most of the cases are caused because the relevant header files are not added, and some are caused by invalid parameters (of course, the invalid parameters may also be because the header files are not added, see below).


Related error solutions - adding header files:

Error content one:

    1. Unresolved inclusion: <jni.h>, Unresolved inclusion: <stdio.h>, Unresolved inclusion: <malloc.h>, Unresolved inclusion: <Android/log .h>, ...
    2. Function '__android_log_print' could not be resolved, Type 'JNIEnv' could not be resolved, Type 'jstring' could not be resolved, Type 'jclass' could not be resolved, Function 'malloc' could not be resolved not be resolved, Function 'memcpy' could not be resolved, Method 'FindClass' could not be resolved, Type 'jsize' could not be resolved, Symbol 'NULL' could not be resolved, ...

Workaround:

    Right click on project - -> Properties --> Left C/C++ General --> Paths and Symbols -->

                                                                                                                                                                 | __>GNU C(.c) __|

${NDKROOT}\platforms\android-18\arch-arm\usr\include
Error content two:

    1. Unresolved inclusion: <iostream>, Unresolved inclusion: <fstream>, Symbol 'std' could not be resolved, ..

    2, Type 'fstream' could not be resolved, Symbol 'in' could not be resolved, Method 'seekg' could not be resolved, Method 'read' could not be resolved, .. .Solution

:

    Add the path (see the above solution for the steps):

${NDKROOT}\sources\cxx-stl\gnu-libstdc++\4.8\include , ${NDKROOT}\sources\cxx-stl\gnu-libstdc++\4.8\ libs\armeabi\include

error content three:

    Invalid arguments 'Candidates are: void * malloc(?)', Invalid arguments 'Candidates are: void * memcpy(void *, const void *, ?)'

Solution:

    Add a path (see the above solution for the steps):

${NDKROOT }\toolchains\arm-Linux-androideabi-4.8\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.8\include




related error solution - symbol replacement:


sometimes you will encounter such an error when compiling: Invalid
arguments 'Candidates are:std::basic_istream<char,std::char_traits<char>> & read(char *, ?)', although we have added the corresponding header file, there are still errors such as invalid parameters, the error message '?' in indicates invalid parameter.

When encountering this kind of error, you can index to the corresponding function (ctrl+click on the function) read to view the parameter type in the function definition. The parameter type in the header file indexed by this function is streamsize, but long is used when using it.

Solution:


Right click on the project --> Properties --> C/C++ General on the left --> Paths and Symbols --> Symbols on the right --> GNU C++(.cpp) --> Add

                                                                                                                                                              | __>GNU C(.c) __|

The value of Name: streamsize, the value of Value: long

After the addition is complete, click OK, and the error disappears.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326407541&siteId=291194637