[Libav-user] Compile with g++

Michael Chisholm chisholm at mitre.org
Tue Oct 8 19:48:41 CEST 2013


On 10/7/2013 6:56 PM, James Board wrote:
>> But if you're compiling pure C code, why not use a C compiler?
>
>
> I'm not compiling pure C code.  I'm compiling C++ code and I want
> to call the libav surboutines from C++ code.  How do I do this?
>

One of your questions was:

"How difficult would it be to compile the examples in the doc/examples
directory with a C++ compiler?"

Those are C programs, so just use a C compiler for them.  That's all I 
meant.

Yes, you can call C functions from a C++ program.  I think many C header 
files have a guard like:

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

to make sure C++ compilers don't mangle the symbols, but the headers I 
use don't have that.  So I just added it myself, around my C includes:

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

and then you can call them normally from your C++ apps.

Andy




More information about the Libav-user mailing list