[Libav-user] Compile with g++

Michael Chisholm chisholm at mitre.org
Wed Oct 9 21:02:37 CEST 2013


On 10/8/2013 7:00 PM, Michael Chisholm wrote:
> On 10/8/2013 6:19 PM, Carl Eugen Hoyos wrote:
>> Michael Chisholm <chisholm at ...> writes:
>>
>>> demuxing.c: In function 'int main(int, char**)':
>>> demuxing.c:261:66: error: invalid conversion from 'void*' to 'uint8_t**
>>> {aka unsigned char**}' [-fpermissive]
>>>            audio_dst_data = av_mallocz(sizeof(uint8_t *) * nb_planes);
>>>                                                                     ^
>>
>> demuxing.c is a C program, if you want to compile it
>> with C++ (why?) you will have to convert it to C++,
>> just as with any other C program.
>> (Nothing about this is FFmpeg specific.)
>>
>
> Of course I wouldn't normally compile a C application with other than a
> C compiler.  There is overlap between C and C++, and the above was just
> an experiment which basically shows that ffmpeg strays outside the
> overlapping region.  And I know as a C project, you have no obligation
> to make the code "C++-friendly".
>
>>> Is that the kind of error you are seeing (this is from ffmpeg 2.0.1)?
>>
>>> I am admittedly using an older version of libav (0.8.6)
>>
>> Just to make sure: This is known to broken (and said to
>> be exploitable) so please understand that we cannot
>> support it here.
>>
>
> Yeah, I wouldn't ask for support for that here.  But if James is willing
> to use it, perhaps that will better fit his need.  Or maybe there is an
> earlier version of ffmpeg which is more C++-friendly.  And of course he
> can always use his API-indirection idea to wrap C++-unfriendly APIs with
> C++-friendly ones.
>

Having a fresher head today, I realize this still wasn't a good test; 
you really need a C++ app which uses libav APIs to test this, not a C 
app.  Or, you could try to see if you can get the C app working by 
changing only the .c file, not any headers.  That's easier, it means I 
don't have to start a new app from scratch.  So that's what I did, and I 
was able to get demuxing.c to compile with a C++ compiler, without 
modifying headers.

I just did the following:
- added casts to "frame->format" in a few places
- removed use of the "av_ts2timestr" macro, since it expanded to code 
that produced a compile error [1]
- Compiled with -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
- Added extern "C" {...} around the includes
- Added cast to the return value of av_mallocz().

So my point to all this is, the ffmpeg-2.0.1 headers aren't completely 
C++-friendly, but it's not as bad as I thought.  I was able to work 
around the problems easily, with this simple test app.

fyi,
Andy

1.

c:/.../ffmpeg-2.0.1/include/libavutil/timestamp.h:72:94: error:
  taking address of temporary array
  #define av_ts2timestr(ts, tb) 
av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
                                                                ^
demuxing.c:87:20: note: in expansion of macro 'av_ts2timestr'
                     av_ts2timestr(frame->pts, &video_dec_ctx->time_base));
                     ^







More information about the Libav-user mailing list