包含< libavformat/avformat.h>时出错在Mac上使用clang的FFMPEG项目中 [英] Error inclunding <libavformat/avformat.h> in FFMPEG project on a Mac using clang

查看:135
本文介绍了包含< libavformat/avformat.h>时出错在Mac上使用clang的FFMPEG项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 remuxing.c示例时遇到麻烦代码.我收到以下错误.我已经确认可以在/usr/local/include中找到文件.我正在运行macOS Sierra 10.12.6.

I'm having trouble running the remuxing.c example code. I get the following error. I have confirmed that the files can be found in /usr/local/include. I am running macOS Sierra 10.12.6.

$ cc -v playground/remuxing.c
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecat
ed-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-v
erifier -discard-value-names -main-file-name remuxing.c -mrelocation-model pic -pic-level 2 -mthread-mo
del posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target
-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Library/Developer/Comman
dLineTools/usr/lib/clang/9.0.0 -fdebug-compilation-dir /Users/myuser/github/personal/synthesthesi
a -ferror-limit 19 -fmessage-length 103 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fenc
ode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/
folders/8s/2xc3v8dd7zz2c2trymzybvd534bnhg/T/remuxing-819223.o -x c playground/remuxing.c
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin16.7.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out /var/folders/8s/2xc3v8dd7zz2c2trymzybvd534bnhg/T/remuxing-819223.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_av_dump_format", referenced from:
      _main in remuxing-819223.o
  "_av_freep", referenced from:
      _main in remuxing-819223.o
  "_av_interleaved_write_frame", referenced from:
      _main in remuxing-819223.o
  "_av_mallocz_array", referenced from:
      _main in remuxing-819223.o
  "_av_packet_unref", referenced from:
      _main in remuxing-819223.o
  "_av_read_frame", referenced from:
      _main in remuxing-819223.o
  "_av_rescale_q", referenced from:
      _main in remuxing-819223.o
  "_av_rescale_q_rnd", referenced from:
      _main in remuxing-819223.o
  "_av_strerror", referenced from:
      _av_make_error_string in remuxing-819223.o
  "_av_write_trailer", referenced from:
      _main in remuxing-819223.o
  "_avcodec_parameters_copy", referenced from:
      _main in remuxing-819223.o
  "_avformat_alloc_output_context2", referenced from:
      _main in remuxing-819223.o
  "_avformat_close_input", referenced from:
      _main in remuxing-819223.o
  "_avformat_find_stream_info", referenced from:
      _main in remuxing-819223.o
  "_avformat_free_context", referenced from:
      _main in remuxing-819223.o
  "_avformat_new_stream", referenced from:
      _main in remuxing-819223.o
  "_avformat_open_input", referenced from:
      _main in remuxing-819223.o
  "_avformat_write_header", referenced from:
      _main in remuxing-819223.o
  "_avio_closep", referenced from:
      _main in remuxing-819223.o
  "_avio_open", referenced from:
      _main in remuxing-819223.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

推荐答案

库由两部分组成:接口(<libavformat/avformat.h>)和实现.您必须同时包含两者.

A library consists of two parts: the interface (<libavformat/avformat.h>) and the implementation. You must include both.

如果没有avformat.h文件,则会收到有关文件丢失或使用未定义函数的错误消息.您没有收到这些错误消息,因此我们可以确定您已包含avformat.h.

If you do not have the avformat.h file, you would get an error about a missing file or use of an undefined functions. You are not getting these error messages, so we can be confident that you avformat.h is being included.

如果不与库链接,则会出现未定义的符号错误.这些是您遇到的错误,通常必须与-lavformat链接,但是根据库搜索路径,您可能还需要传递-L选项.另外,您可以指定库的完整路径,该路径类似于/usr/local/lib/libavformat.a/usr/local/lib/libavformat.dylib(或其他名称),但是通常不建议这样做,因为它会使您的构建脚本更加脆弱.

If you don't link with the library, you will get undefined symbol errors. These are the errors you are getting, typically you must link with -lavformat but depending on the library search paths you might need to pass a -L option as well. Alternatively, you can specify the full path to the library, which will be something like /usr/local/lib/libavformat.a or /usr/local/lib/libavformat.dylib (or something else), but this is not typically recommended because it can make your build scripts more fragile.

我希望看到这样的东西:

I would expect to see something like this:

cc -Wall -Wextra playground/remuxing.c -lavformat

如果/usr/local/lib不在您的图书馆搜索路径中,则应使用-L添加它:

If /usr/local/lib is not in your library search path you would add it with -L:

cc -Wall -Wextra playground/remuxing.c \
    -L/usr/local/lib -lavformat

如果libavformat是带有依赖项的静态库,则还需要包括那些依赖项.如果它是动态库,则没有必要.如果您的系统上已安装pkg-config,则可以完全避免该问题:

If libavformat is a static library with dependencies you will also need to include those dependencies. If it is a dynamic library, this is unnecessary. You can avoid the question altogether by using pkg-config if it is installed on your system:

cc -Wall -Wextra playground/remuxing.c \
    $(pkg-config --cflags --libs avformat)

(不确定avformat在这里是否正确,但是一般来说,除非您有充分的理由不使用它,否则通常要使用pkg-config查找库.)

(Not sure if avformat is the right name here, but in general you want to use pkg-config to find libraries unless you have a good reason not to use it.)

这篇关于包含&lt; libavformat/avformat.h&gt;时出错在Mac上使用clang的FFMPEG项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆