Visual Studio Code: errors with native-lib.cpp from Android Studio NDK

I am trying to build an android app using Android Studio for one of my classes and I would like to use Visual Studio Code as an IDE. I believe that I managed to find the all include pathes needed for the header file jni.h, however I am still getting errors with one of the lines in the native-lib.cpp file generated by the project. Am I just missing another header file or something. I am brand new to Android Studio, but very well rounded with C++. Which is why I am so confused on these errors it is giving, because I do not even know what the line of code causing the error does. I know about defines, macros, and even externs, but I do not understand what "extern "C"" does at all never seen something like that before. I am posting the native-lib.cpp file with the errors, a screenshot of exactly where it is saying the errors, the errors themselves, and the c_cpp_properties.json from VSCode. I would greatly appreciate anyone’s help with this, thanks in advance.

native-lib.cpp

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

extern "C" JNIEXPORT jstring JNICALL // Errors are here
Java_com_example_mobileappproject_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

enter image description here

Errors:

explicit type is missing (‘int’ assumed)C/C++(260)

identifier "NIEXPORT" is undefinedC/C++(20)

expected a ‘;’C/C++(65)

expected a ‘;’C/C++(65)

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/mnt/c/Program Files/Android/Android Studio/jre/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Source: Windows Questions C++

LEAVE A COMMENT