错误inclunding 在Mac上使用铛FFMPEG项目(Error inclunding

2019-10-28 15:47发布

我在跑的麻烦remuxing.c示例代码 。 我碰到下面的错误。 我已经证实,这些文件中可以找到/usr/local/include 。 我运行MacOS的塞拉利昂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)

Answer 1:

库由两个部分组成:接口( <libavformat/avformat.h>和实施。 你必须同时包括。

如果你没有avformat.h文件,你会得到一个错误有关丢失的文件或使用未定义功能。 你没有得到这些错误信息,所以我们可以相信,你avformat.h被包括在内。

如果你不与库链接,你会得到一个未定义符号错误。 这些是你所得到的错误,通常必须使用链接-lavformat但根据库搜索路径可能需要传递一个-L选项,以及。 或者,您可以指定完整路径到库,这将是像/usr/local/lib/libavformat.a/usr/local/lib/libavformat.dylib (或别的东西),但通常不推荐因为它可以让你的构建脚本更加脆弱。

我希望看到这样的事情:

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

如果/usr/local/lib是不是在你的库搜索路径,你会用它添加-L

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

如果libavformat流是依赖静态库,你还需要包括那些依赖关系。 如果它是一个动态库,这是不必要的。 您可以通过使用完全避免这个问题pkg-config如果在系统上安装:

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

(不知道是否avformat是正确的名字在这里,但一般要使用pkg-config找到库,除非你有一个很好的理由不使用它。)



Answer 2:

另外这个应该工作过:
configure “荷兰国际集团的FFmpeg,在同一个目录,使用: make examples这通常会编译所有的例子

看来这还提到这里: FFmpeg的:建筑如C代码



文章来源: Error inclunding in FFMPEG project on a Mac using clang