clang ++:错误:链接器命令失败,使用ffmpeg在cpp中退出代码为1(使用-v查看调用)

问题描述 投票:1回答:1
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

我看到了这个linklink2。但是,它没有完成。

我的jni文件夹:

enter image description here

Android.mk文件

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文件

#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());
}

当我构建ndk时,会发生此错误。

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>

为什么会这样native-lib.cpp:16: undefined reference av_register_all

我在jni文件夹中添加了所有必需的库,但是为什么会出现此错误和此native-lib.cpp:16: undefined reference av_register_all?我该如何解决?

c++ makefile ffmpeg android-ndk linker
1个回答
2
投票

我在jni文件夹中添加了所有必需的库,但是为什么会出现此错误以及此native-lib.cpp:16:未定义的引用av_register_all出现?

仅将库放到项目中是不够的。您的Android.mk中没有任何链接指令。因此,即使您的库在那里,在编译本机库时也不会链接。因此,您的未定义引用...

[我建议您看看this帖子,重点关注那些LOCAL_C_INCLUDESLOCAL_LDLIBS变量。您必须在项目中做类似的事情。

© www.soinside.com 2019 - 2024. All rights reserved.