Open CTXz opened 6 years ago
With g++ version 5.4.0 CPP 11
I tried as below,
av_always_inline char *av_err2str_inline(int errnum) { static char str[AV_ERROR_MAX_STRING_SIZE]; memset(str, 0, sizeof(str)); return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum); }
fprintf(stderr, "Could not open codec: %s\n", av_err2str_inline(ret));
As mentioned at http://libav-users.943685.n4.nabble.com/Libav-user-g-4-7-2-fails-to-compile-av-err2str-td4656417.html
I prefer @sampleref 's answer, to be specified, put the below in your header
// fix temporary array error in c++1x
#ifdef av_err2str
#undef av_err2str
av_always_inline char* av_err2str(int errnum)
{
// static char str[AV_ERROR_MAX_STRING_SIZE];
// thread_local may be better than static in multi-thread circumstance
thread_local char str[AV_ERROR_MAX_STRING_SIZE];
memset(str, 0, sizeof(str));
return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
}
#endif
updated again:
#ifdef av_err2str
#undef av_err2str
#include <string>
av_always_inline std::string av_err2string(int errnum) {
char str[AV_ERROR_MAX_STRING_SIZE];
return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
}
#define av_err2str(err) av_err2string(err).c_str()
#endif // av_err2str
Followed blindly @vacing it worked perfectly
@sathyaprakashk updated my answer
Hi, guys, thanks for the fix, as of today, I see that I still see such error when using G++ with the latest ffmpeg library. Thanks for your solutions!
The same applies to av_ts2timestr:
#ifdef av_ts2timestr
#undef av_ts2timestr
#include <string>
av_always_inline std::string av_ts2timestring(int64_t ts, AVRational *tb) {
char str[AV_TS_MAX_STRING_SIZE];
return av_ts_make_time_string(str, ts, tb);
}
#define av_ts2timestr(ts, tb) av_ts2timestring((ts), (tb)).c_str()
#endif // av_ts2timestr
av_err2str makes use of C array constructs that break newer versions of G++.
See: https://ffmpeg.org/pipermail/libav-user/2013-January/003458.html
Error:
G++:
To work this issue around, I've placed the following macros, as suggested by this mail from the Libav-user mailinglist, after line line 40:
With av_err2str being overwritten, compilation succeeds.