Print log error undefined reference to `_ _ android_log_print' in Android jni

when creating a project, checking Include CPP support,IDE will automatically generate a native-lib.cpp file, and it is normal to print log in the native-lib.cpp file.

-sharpinclude <jni.h>
-sharpinclude <string>
-sharpinclude "android_log.h"

extern "C"
JNIEXPORT jstring JNICALL
Java_org_ffmpeg_MainActivity_stringFromJNI(JNIEnv* env, jobject /* this */) {
    std::string hello = "Hello from CPP";
    LOGI("native-lib.cpp | Hello, world");
    return env->NewStringUTF(hello.c_str());
}
The contents of the android_ logh header file introduced by

are as follows:

-sharpinclude <android/log.h>
-sharpifndef LOG_TAG
    -sharpdefine LOG_TAG "FFmpeg"
-sharpendif
-sharpdefine LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
-sharpdefine LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

log: can be printed normally at this time


04-05 21:26:40.953 2751-2751/? I/FFmpeg: native-lib.cpp | Hello, world

I created a new file called FFmpeg.cpp, which reads as follows:

-sharp FFmpeg.cpp
-sharpinclude <jni.h>
-sharpinclude <string>
-sharpinclude "android_log.h"

extern "C"
JNIEXPORT jint JNICALL
Java_org_ffmpeg_FFmpeg_exec(JNIEnv* env, jobject /* this */, jstring cmd) {
    LOGI("FFmpeg.cpp | exec()");
    return 12345;
}

if you print Log, in a FFmpeg.cpp file, you will get an error:

Build command failed.
Error while executing process D:\Android_SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\workspace_as\FFmpeg\app\.externalNativeBuild\cmake\debug\mips64 --target native-lib}
[1/3] Building CXX object CMakeFiles/ffmpeg.dir/src/main/cpp/ffmpeg.cpp.o
[2/3] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\mips64\libffmpeg.so
FAILED: cmd.exe /C "cd . && D:\Android_SDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clangPP.exe  --target=mips64el-none-linux-android --gcc-toolchain=D:/Android_SDK/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=D:/Android_SDK/ndk-bundle/sysroot -fPIC -isystem D:/Android_SDK/ndk-bundle/sysroot/usr/include/mips64el-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fintegrated-as -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a --sysroot D:/Android_SDK/ndk-bundle/platforms/android-21/arch-mips64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libffmpeg.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\mips64\libffmpeg.so CMakeFiles/ffmpeg.dir/src/main/cpp/ffmpeg.cpp.o  -lm "D:/Android_SDK/ndk-bundle/sources/cxx-stl/gnu-libstdcPP/4.9/libs/mips64/libgnustl_static.a" && cd ."
CMakeFiles/ffmpeg.dir/src/main/cpp/ffmpeg.cpp.o: In function `Java_org_ffmpeg_FFmpeg_exec":
D:\workspace_as\FFmpeg\app\src\main\cpp/ffmpeg.cpp:9: undefined reference to `__android_log_print"
clangPP.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

as long as the line LOGI ("FFmpeg.cpp | exec ()"); is removed, there will be no error.

04-05 21:33:17.432 3356-3356/? I/FFmpeg: native-lib.cpp | Hello, world
04-05 21:33:17.432 3356-3356/? I/FFmpeg: MainActivity.java | FFmpeg.exec():12345

this problem is so weird that I don"t have a clue all day. If there is a big god who knows the solution, please let me know. Thank you very much!

Mar.03,2021

CMAKELIST links your own cpp to the log library

find_library (- sharp Sets the name of the path variable.

)
          log-lib

          -sharp Specifies the name of the NDK library that
          -sharp you want CMake to locate.
          log )
          

target_link_libraries (- sharp Specifies the target library.

)
                   test.lib  

                   -sharp Links the target library to the log library
                   -sharp included in the NDK.
                   ${log-lib} )
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32bc0-2be1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32bc0-2be1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?