Xcode, ffmpeg and mac

So for the last 2 hours I’ve been getting errors trying to compile some C++ code on my mac that makes use of ffmpeg. For clarity, I’m using a modern MBP, Xcode and C++ to try and compile some simple ffmpeg code to spit out a list of stuff I can’t even remember the reason for right now.

...Undefined symbols for architecture x86_64:
"avcodec_register_all()...

This error was telling me that the linker can’t find a particular library required for compiling. So I tried rebuilding ffmpeg a few times with different options, I tried linking the include and lib directories to Xcode a couple of different ways, I tried changing the code several times too, I even tried compiling via terminal with g++, all with no luck.

So, tired as hell, I give it one more try. I realise that, thanks to some crazy Chinese forum with snippets of English on it, ffmpeg uses C, not C++. So I had to change my header includes to reflect that.


#ifdef __cplusplus
extern "C" {
#include "libavformat/avformat.h"
}
#endif

instead of:

#include <libavformat/avformat.h>

An unbelievably simple fix to a nightmare-ish problem, such is the life of a programmer.

So, I don’t write a lot of stuff here anymore but decided to put this up just in case someone else finds themselves in the same situation in the distant future.

Bookmark the permalink.

Comments are closed.