ffmpeg - compiling an example file
last updated: Sep 23, 2024
I wanted to compile a file from the ffmpeg examples directory, since I'm considering writing golang that links directly to ffmpeg via cgo.
I don't use C often enough to remember how everything works, so I have to re-figure-out how to compile stuff every time. Here's what I ended up with:
clang \
-I/opt/homebrew/Cellar/ffmpeg/7.0.2/include \
-L/opt/homebrew/Cellar/ffmpeg/7.0.2/lib/ \
-lavutil -lavfilter -lavformat \
decode_filter_video.c
-I
: tells clang to search the given directory for header files- You can use the
C_INCLUDE_PATH
environment variable instead if you prefer - homebrew puts all its include files in
/opt/homebrew/include
, so if you want to be more general you can add that toC_INCLUDE_PATH
in your shell initialization, or use that as the-I
argument
- You can use the
-L
: tells clang to search the given directory for objects to link- You can use the
LIBRARY_PATH
environment variable instead- The difference between
LIBRARY_PATH
andLD_LIBRARY_PATH
is that the latter is used at runtime for loading dynamic libraries
- The difference between
- You can use the
-l<libname>
: tells clang to link the library given by<libname>
- I had to just kind of guess at which ones of these I needed to resolve all the undefined symbols errors I was getting
- Is there a way to have the computer figure out which libraries you need, or is it just required for the programmer to know which
-l<whatever>
flags need to be included?
clangd
Without any configuration, clangd won't be able to find the header files you need. Here's a config file I created to give it the header directory and add -Wall
. Save it to .clangd
:
CompileFlags:
Add:
- "-Wall"
- "-I/opt/homebrew/Cellar/ffmpeg/7.0.2/include"