C++ 使用ffmpeg链接进行开发失败
我写测试ffmpeg并调用ffmpeg函数,但它总是告诉我链接错误:找不到ffmpeg函数: 这是我的代码:C++ 使用ffmpeg链接进行开发失败,c++,ffmpeg,linker,C++,Ffmpeg,Linker,我写测试ffmpeg并调用ffmpeg函数,但它总是告诉我链接错误:找不到ffmpeg函数: 这是我的代码: #ifdef __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS #endif #ifndef INT64_C #define INT64_C(c) (c ## LL) #define UINT64_C(c) (c ## ULL) #endif #include <libavutil/imgutils.h> #inclu
#ifdef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
static const char *src_filename = NULL;
static const char *video_dst_filename = NULL;
static const char *audio_dst_filename = NULL;
static AVFormatContext *fmt_ctx = NULL;
int main(int argc, char **argv) {
int ret = 0;
if (argc != 4) {
fprintf(stderr, "usage: %s input_file video_output_file audio_output_file\n"
"API example program to show how to read frames from an input file.\n"
"This program reads frames from a file, decodes them, and writes decoded\n"
"video frames to a rawvideo file named video_output_file, and decoded\n"
"audio frames to a rawaudio file named audio_output_file.\n",
argv[0]);
exit(1);
}
// src_filename = argv[1];
src_filename = "/tmp/a.mp4";
video_dst_filename = argv[2];
audio_dst_filename = argv[3];
/* open input file, and allocate format context */
if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) {
fprintf(stderr, "Could not open source file %s\n", src_filename);
exit(1);
}
avformat_close_input(&fmt_ctx);
}
和终端输出:
Undefined symbols for architecture x86_64:
"avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)", referenced from:
_main in main-f2a6f0.o
"avformat_close_input(AVFormatContext**)", referenced from:
_main in main-f2a6f0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
那么谁能告诉我原因。
-lavformat
需要在编译命令中的main.cpp
之后,我添加它并重试。它显示了相同的错误。您需要在extern“C”