Domanda

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.

I am working on OS X (10.8.3) and have installed libav through the following steps.

First, install dependancies using 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)

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.

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:

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. 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. The C code itself compiles fine when I remove the av_register_all() call.

The include for libavformat looks like this: #include "libavformat/avformat.h"

Any help is appreciated. I have tried adding -arch x86_64 to the CFLAGS export, but it made no difference.

È stato utile?

Soluzione

The undefined symbols error occur because you do not tell the linker to link against libav.

Try using gcc -Wall -o base -lav base.c. The -l flag tells the linker to use the libav library.

Note that the lib part is left out when using the -l flag!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top