[FFmpeg-devel] Debug builds and if (ARCH_...) linking issues

Hendrik Leppkes h.leppkes at gmail.com
Thu Apr 13 10:30:27 EEST 2017


On Thu, Apr 13, 2017 at 9:20 AM, Aaron Levinson <alevinsn at aracnet.com> wrote:
> I wanted to build a debug build of ffmpeg using Visual C++ today, one
> without any optimizations.  This implies the use of the -Od compiler option.
> Unfortunately, I quickly discovered that the build fails soon after it
> starts because it can't find certain architecture-specific references.  For
> example, in libavutil/cpu.c, there is the following:
>
>     if (ARCH_AARCH64)
>         return ff_get_cpu_flags_aarch64();
>
> The linker couldn't find ff_get_cpu_flags_aarch64 (and other similar
> references) and failed.  This isn't an issue when optimizations are turned
> on because the compiler notices that ARCH_AARCH64 is defined as 0 and
> eliminates the relevant code.
>
> Effectively, successful builds of ffmpeg depend on this compiler
> optimization.  This appears to have been the standard practice in the ffmpeg
> code base for at least the last few years, but it is unclear to me why this
> approach is being used, since, in addition to depending on specific compiler
> behavior, it prevents fully debug builds from succeeding, at least with
> Visual C++.
>
> If people like the if (ARCH_...) syntax, while it wouldn't look quite as
> nice, what's wrong with doing the following:
>
> #if ARCH_AARCH64
>     if (ARCH_AARCH64)
>         return ff_get_cpu_flags_aarch64();
> #endif
>
> Another, much less desirable option is to use #pragma optimize for the
> relevant functions in ffmpeg to turn optimizations on for specific
> functions.
>
> A third option would be to build only the relevant files with optimizations
> turned on, but this will end up making the Makefiles more complicated, and
> the relative simplicity of the Makefiles is appealing.
>
> For now, I'm using both -Od and -Og with Visual C++ (-Og turns on some
> optimizations, but not as much as -O1 or -O2), but this isn't the same as a
> true debug build.
>

We require Dead-Code-Eliminiation to be performed at all times in a
FFmpeg build, so your compiler needs to do this for a build to
succeed.
You can find the reasonings and discussions about this in the Mailing
List archives, it comes up once in a while.

If you are actually working on some code, I can only recommend to use
the pragma in the files you are working on. Its not that bad, really.

- Hendrik


More information about the ffmpeg-devel mailing list