Issue
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I saw this link and link2. But, it not done.
My jni folder:
Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += ./include
LOCAL_MODULE := native-lib
LOCAL_CFLAGS := -DSTDC_HEADERS -std=c99
LOCAL_CFLAGS := -Wno-pointer-sign
LOCAL_ARM_MODE := arm
APP_OPTIM := release
LOCAL_SRC_FILES := \
./native-lib.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
native-lib.cpp file
#include <jni.h>
#include <string>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/opt.h"
}
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_m_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
av_register_all();
return env->NewStringUTF(hello.c_str());
}
When I build ndk this error occurs.
D:\Github\n>ndk-build
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16.
[arm64-v8a] Compile++ : native-lib <= native-lib.cpp
[arm64-v8a] SharedLibrary : libnative-lib.so
./obj/local/arm64-v8a/objs/native-lib/./libmp3lame/native-lib.o: In function `Java_com_example_m_MainActivity_stringFromJNI':
D:\Github\n/jni/./libmp3lame/native-lib.cpp:16: undefined reference to `av_register_all'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [D:/install/sdk/ndk/21.0.6113669/build//../build/core/build-binary.mk:725: obj/local/arm64-v8a/libnative-lib.so] Error 1
D:\Github\n>ndk-build -v
GNU Make 4.2.1
Built for x86_64-w64-mingw32
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
D:\Github\n>
why it comes like this native-lib.cpp:16: undefined reference av_register_all
?
I added all the required libs in my jni folder but, why this error and this native-lib.cpp:16: undefined reference av_register_all
comes?
How can I solve this?
Solution
I added all the required libs in my jni folder but, why this error and this native-lib.cpp:16: undefined reference av_register_all comes?
Just dropping the libraries inside your project is not enough. You don't have any link directives in your Android.mk. So even though your library is there it won't get linked when your native-lib gets compiled. Hence your undefined references ...
I suggest you have a look at this post focusing on those LOCAL_C_INCLUDES
and LOCAL_LDLIBS
variables. You'll have to do something similar in your project.
Answered By - dragosht
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.