简体   繁体   English

在C代码中使用libavformat,未定义的x86_64符号

[英]Using libavformat in C code, undefined x86_64 symbols

I am working on a project where I have to create a simple C program that makes use of libavformat to convert a file from one format to another. 我正在开发一个项目,我必须创建一个简单的C程序,它利用libavformat将文件从一种格式转换为另一种格式。

I am working on OS X (10.8.3) and have installed libav through the following steps. 我正在使用OS X(10.8.3)并通过以下步骤安装了libav

First, install dependancies using Homebrew: 首先,使用Homebrew安装依赖项:

brew install yasm zlib faac lame speex libogg libvorbis theora libvpx x264
XviD openjpeg opencore-amr freetype

Next, download libav from here: http://libav.org/download.html (using the libav 9 "plain 9" release) 接下来,从这里下载libav: http ://libav.org/download.html(使用libav 9 "plain 9"发布)

Finally, configure with the following commands: 最后,使用以下命令进行配置:

export CFLAGS="-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5/ -I/usr/local/Cellar/lame/3.99.5/include/lame/"

./configure --enable-gpl --enable-libx264 --enable-libxvid --enable-version3
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-nonfree
--enable-libfaac --enable-libmp3lame --enable-libspeex --enable-libvorbis
--enable-libtheora --enable-libvpx --enable-libopenjpeg --enable-libfreetype
--enable-doc --enable-gnutls --enable-shared --arch=x86_64

Everything compiles correctly and gives a list of supported codecs, encoders, decoders, muxers, demuxers, etc. 所有内容都能正确编译,并提供支持的编解码器,编码器,解码器,复用器,解复用器等列表。

I then run make && sudo make install . 然后我运行make && sudo make install

However, once I try to make use of av_register_all() and some other critical functions in my own C code, I get the following error: 但是,一旦我尝试在我自己的C代码中使用av_register_all()和一些其他关键函数,我会收到以下错误:

Undefined symbols for architecture x86_64:
  "_av_register_all", referenced from:
      _main in base-bPKLay.o

I have tried compiling it using gcc -Wall base.c -o base as well as clang -Wall base.c -o base , but both give the above error. 我尝试使用gcc -Wall base.c -o base以及clang -Wall base.c -o base编译它,但两者都给出了上述错误。 I fear that something is wrong with how the libraries are linked, but I am not experienced enough with C programming in general to know where to look next. 我担心库的链接方式有问题,但我对C编程的经验不足以了解下一步要查看的位置。 The C code itself compiles fine when I remove the av_register_all() call. 当我删除av_register_all()调用时,C代码本身编译得很好。

The include for libavformat looks like this: #include "libavformat/avformat.h" libavformat的#include "libavformat/avformat.h"如下所示: #include "libavformat/avformat.h"

Any help is appreciated. 任何帮助表示赞赏。 I have tried adding -arch x86_64 to the CFLAGS export, but it made no difference. 我已经尝试将-arch x86_64添加到CFLAGS导出中,但它没有任何区别。

The undefined symbols error occur because you do not tell the linker to link against libav. 发生未定义的符号错误是因为您没有告诉链接器链接libav。

Try using gcc -Wall -o base -lav base.c . 尝试使用gcc -Wall -o base -lav base.c The -l flag tells the linker to use the libav library. -l标志告诉链接器使用libav库。

Note that the lib part is left out when using the -l flag! 请注意,使用-l标志时, lib部分被省略了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM