[Libav-user] Building with MSVC toolchain resulting in seeking problem?

Bjoern Drabeck bjoern.drabeck at gmail.com
Fri Mar 22 09:26:20 CET 2013

>   > I have got that to build, however compared to builds
>> > from the zeranoe site (and also builds I have asked a
>> > friend of mine to make for me using mingw with gcc),
>> > I always end up with seeking problems.
>>  This is surprising.
>> Are you sure that you are testing the same versions?
>  I have downloaded the zeranoe build marked as 1.1.3 and I also got
> http://ffmpeg.org/releases/ffmpeg-1.1.3.tar.bz2 and built that myself..
> so I would say it's the same version. However I got the same problem with
> previous versions too (tried 1.0.1, and 1.1 for example).
>> Did you try to disable optimizations?
>>  For some reason I get build errors as soon as I
> use --disable-optimizations:
>  LD libavutil/avutil-52.dll
>    Creating library libavutil/avutil.lib and object libavutil/avutil.exp
> cpu.o : error LNK2019: unresolved external symbol _ff_get_cpu_flags_ppc
> referenced in function _av_get_cpu_flags
> cpu.o : error LNK2019: unresolved external symbol _ff_get_cpu_flags_arm
> referenced in function _av_get_cpu_flags
> libavutil/avutil-52.dll : fatal error LNK1120: 2 unresolved externals
> make: *** [libavutil/avutil-52.dll] Error 1
>  If I don't disable optimizations I don't get that and it builds fine...
> but no idea about that (I have never really looked into the ffmpeg code
> except for the public headers)
> Parts of ffmpeg source code assume the compiler will remove the body of a
> conditional if the condition is always false, for example from
> libavutil.c/av_get_cpu_flags():
> int av_get_cpu_flags(void)
> {
>     if (checked)
>         return flags;
>     if (ARCH_ARM) flags = ff_get_cpu_flags_arm();
>     if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
>     if (ARCH_X86) flags = ff_get_cpu_flags_x86();
>     checked = 1;
>     return flags;
> }
> If ARCH_ARM is the constant 0, the code assumes this reference to
> ff_get_cpu_flags_arm() will disappear.  Treats that as an optimization, so
> if you turn off optimizations, the compiler will generate code to call
> ff_get_cpu_flags_arm, but that function won't exist if ARCH_ARM is false.
> To get around that, I've used flags like these to compile a less optimized
> version for testing purposes:
> --toolchain=msvc --optflags='-Zi -Og -Oy- -arch:SSE2' --extra-cflags='-Gy
> -MDd' --extra-ldflags='-OPT:REF -DEBUG -VERBOSE' --enable-shared
> I've been using VC10.  The thing that's handy for me is that it generates
> .pdb files (via the -Zi flag) and I can mostly step through code with the
> VC10 debugger.
> I had to modify the config.mak to get rid of some conflicting flags,
> running the configuration script would add -Z7 (which contradicts -Zi).  It
> also would add -Oy which is the opposite of -Oy-, so I manually removed it.
> --Johno
I have had some time to play around with the configure (but please bear in
mind that this was my first time ever modifying a configure, so I am not
quite sure these things make sense - but please feel free to correct me, am
happy to learn more about this!).

Anyway, my goal was to come to a configuration as described by John above,
so that I can step through code with the MSVC debugger, and so far seems to
work (ie compiled fine, and also seems can debug, but need to test more,
but probably only after the weekend)

I tried this on the 1.2 release, with the following configuration options:
--prefix=<my project folder>

I don't need encoders or muxers, so I skipped those, I enabled dxva2
(although it seems it gets enabled by default anyway, not sure though), I
used msvc toolchain with debug enabled, and optimizations disabled but
enabled small (that might be a bit misleading as it leads to -O1 -Oy- which
is an optimization)

Anyway, please see below my changes for the configure, as I said I don't
know if they are really "correct" or might have side effects under other
circumstances, but at least for me it worked to compile without getting any
errors - feedback welcome!

Around line 2430:

added OPT:REF, DEBUG, and VERBOSE options for debug configuration under MSVC

        cc_default="c99wrap cl"
        ld_default="c99wrap link"
+ if enabled debug; then
+ add_ldflags -OPT:REF -DEBUG -VERBOSE
+ fi
        nm_default="dumpbin -symbols"

Around line 2740:

where it set the _cflags_speed and _cflags_size I added check for debug
configuration as well, and under debug added -Oy-

I also appended -MD (under release) and -MDd -Zi (under debug) to the

    elif $_cc 2>&1 | grep -q Microsoft; then
        _ident=$($cc 2>&1 | head -n1)
        _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk
'\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, /
/)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
        _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
+ if enabled debug; then
+ _cflags_speed="-O2 -Oy-"
+ _cflags_size="-O1 -Oy-"
+ else
+ fi
        # Nonstandard output options, to avoid msys path conversion issues,
relies on wrapper to remap it
        if $_cc 2>&1 | grep -q Linker; then
            _ld_o='-out $@'
        _cc_o='-Fo $@'
        _cc_e='-P -Fi $@'
        _cflags='-D_USE_MATH_DEFINES -Dinline=__inline -FIstdlib.h
        if [ $pfx = hostcc ]; then
            append _cflags -Dsnprintf=_snprintf
+ if enabled debug; then
+ append _cflags -MDd -Zi
+ else
+ append _cflags -MD
+ fi
        disable stripping

Around line 4060:

to get rid of some warnings about unknown options I added a check for msvc

+ if disabled msvc; then
enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
+ fi

So do these changes make sense? What can I improve? Anyone willing to try
it (maybe John?)

best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130322/163cd994/attachment.html>

More information about the Libav-user mailing list