2

I would like to create my own project using FFMPEG to build a player, but creating a new file to include ffmpeg library seems not easy. I have configure the ffmpeg and make build.

./configure

./make

The ffmpeg hello world program (myffmpeg.c):

#include <libavformat/avformat.h> int main(int argc, char *argv[]) { av_register_all(); return 0; } 

but it shows

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

Undefined symbols for architecture x86_64:

"av_register_all()", referenced from:

_main in myffmpeg-61ec1b.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation

When I try to link the allformats.o file, which has av_register_all function inside. I got:

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated Undefined symbols for architecture x86_64: "_av_register_input_format", referenced from: _register_all in allformats.o "_av_register_output_format", referenced from: _register_all in allformats.o "_avcodec_register_all", referenced from: _register_all in allformats.o "_ff_a64_muxer", referenced from: _register_all in allformats.o

...

"_ff_yuv4mpegpipe_muxer", referenced from: _register_all in allformats.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

It should be my bad Makefile knowledge, could anyone give me some hint on how to call ffmpeg library functions? Or even how to modify the Makefile to build my own program? Thanks!

*Update: It could be my compiling command problem, is it the way to compile?

g++ myffmpeg.c

1
  • If you want to see some examples, including a Makefile, see doc/examples. Just wrap the headers like in the answer below. Commented Aug 1, 2017 at 9:11

2 Answers 2

5

maybe the problem is that c++ is decorating functions. So the same function compiled with C compiler and C++ looks different to linker. try this:

extern "C" { #include <libavformat/avformat.h> } 

this code means that you told your compiler to not decorate functions in that file.

Sign up to request clarification or add additional context in comments.

1 Comment

We still need this extern, and the pkg-config can work.
1

I think I could answer myself.

g++ -o main.o main.c `pkg-config --cflags --libs libavformat` 

I don't know the reason now, it is from https://soledadpenades.com/2009/11/24/linking-with-ffmpegs-libav/

We still need the extern, see answer below.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.