与/ INCREMENTAL链接时清空导入表:否导入某些dll的库

时间:2013-12-12 11:31:58

标签: visual-c++ dll mingw import-libraries

/INCREMENTAL:NO是visual c中发布配置的默认值。

我已从http://ffmpeg.zeranoe.com/builds/下载了FFmpeg git-3efe5e3 32-bit Dev。 它包含.dll.a.lib个文件。我选择.lib。编译后,ffmpeg dll的导入表为空,程序崩溃。如果我启用/INCREMENTAL,它会编译并运行正常。

test.c

void av_register_all();

int main() {
    av_register_all();
    return 0;
}

_

lib>cl test.c /link /incremental:no avformat.lib ws2_32.lib
lib>dumpbin /IMPORTS test.exe
...
    avformat-55.dll
                4080F4 Import Address Table
                4095E4 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference


    KERNEL32.dll
                408000 Import Address Table
                4094F0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                  143 GetCurrentProcessId
                  110 GetCommandLineA
                  216 HeapFree
...

1 个答案:

答案 0 :(得分:1)

这是binutils中的一个已知错误,它在Zempoe的FFmpeg版本中使用。 在默认情况下,链接器选项中的Microsoft Visual Studio的发布版本>优化>引用= /OPT:REF,它会删除所有FFmpeg引用,因此您在dumpbin /IMPORTS中看不到它们。

您需要按照4.2.1 Linking to FFmpeg with Microsoft Visual C++的说明操作。有两种选择。在链接器选项中指定/OPT:NOREF,由于增加了可执行文件的大小而增加了可执行文件的初始加载时间。或者从.lib生成新的.exp.def文件,例如x86_64:

lib /machine:x64 /def:avcodec-55.def /out:avcodec.lib
lib /machine:x64 /def:avdevice-55.def /out:avdevice.lib
lib /machine:x64 /def:avfilter-4.def /out:avfilter.lib
lib /machine:x64 /def:avformat-55.def /out:avformat.lib
lib /machine:x64 /def:avutil-52.def /out:avutil.lib
lib /machine:x64 /def:postproc-52.def /out:postproc.lib
lib /machine:x64 /def:swresample-0.def /out:swresample.lib
lib /machine:x64 /def:swscale-2.def /out:swscale.lib

另一种选择是自己建立FFmpeg。

另一个选择是加入FFmpeg开发社区并将构建系统从autotools / autoconf / automake移动到CMake。

版主,请修复我破碎的英文。