环境:
centos
mingw
gcc版本:
[root@localhost x264]# x86_64-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-w64-mingw32/4.9.2/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../configure --prefix=/usr --bindir=/usr/bin --includedir=/usr/include --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --with-gnu-as --with-gnu-ld --verbose --without-newlib --disable-multilib --disable-plugin --with-system-zlib --disable-nls --without-included-gettext --disable-win32-registry --enable-languages=c,c++,objc,obj-c++,fortran --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-threads=posix --enable-libgomp --target=x86_64-w64-mingw32 --with-sysroot=/usr/x86_64-w64-mingw32/sys-root --with-gxx-include-dir=/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++
Thread model: posix
gcc version 4.9.2 20141030 (Fedora MinGW 4.9.2-1.el6) (GCC)
配置:
./configure \
--prefix=../windows/x86_64 \
--enable-static \
--enable-pic \
--host=x86_64-w64-mingw32 \
--cross-prefix=x86_64-w64-mingw32-
结果:
1、生成的x264.exe能正常在windows中运行;
2、生成的libx264.a在vs2005的工程中不能被正常链接!!!
测试程序:
#include "stdafx.h"
#include "stdint.h"
#include "x264.h"
int _tmain(int argc, _TCHAR* argv[])
{
x264_param_t param;
x264_encoder_open(¶m);
return 0;
}
1>Linking...
1>VideoEncoder.obj : error LNK2019: unresolved external symbol _x264_encoder_open_148 referenced in function _wmain
1>F:\personal\sourcecode\VideoEncoder\Debug\VideoEncoder.exe : fatal error LNK1120: 1 unresolved externals
分析:
dumpbin /ALL libx264.a > 1.txt
String Table Size = 0x539 bytes
COFF SYMBOL TABLE
000 00000000 DEBUG notype Filename | .file
encoder.c
002 00000000 SECT1 notype () Static | x264_slice_header_init
tag index 00000000 size 00000000 lines 00000000 next function 00000000
004 000002D0 SECT1 notype () Static | mbcmp_init
005 000007D0 SECT1 notype () Static | sprintf
006 00000800 SECT1 notype () Static | snprintf
007 00000820 SECT1 notype () Static | x264_fdec_filter_row
008 00000F00 SECT1 notype () Static | x264_set_aspect_ratio.isra.3
009 00001020 SECT1 notype () Static | x264_encoder_thread_init
00A 00001050 SECT1 notype () Static | x264_nal_end
00B 00001190 SECT1 notype () Static | x264_encoder_encapsulate_nals.constprop.13
00C 00001360 SECT1 notype () Static | x264_encoder_frame_end.part.7
00D 00002870 SECT1 notype () Static | x264_slice_write
00E 00001400 SECT7 notype Static | x264_ue_size_tab
00F 000013EC SECT7 notype Static | x264_mb_chroma_pred_mode_fix
010 00006470 SECT1 notype () Static | x264_slices_write
011 000066B0 SECT1 notype () External | x264_encoder_open_148
012 00000000 SECTB notype Static | .rdata$.refptr.x264_levels
发现libx264.a中是x264_encoder_open_148,而vs2005链接的时候寻找的是_x264_encoder_open_148,因此产生了链接问题。
经查资料,发现是因为msvc在链接c函数时都会加"_",而在linux中使用mingw编译的库却没有加"_",
在configure时增加--extra-cflags="-fleading-underscore":
No working C compiler found.
Makefile:3: config.mak: 没有那个文件或目录
cat: config.h: 没有那个文件或目录
有谁知道解决办法?不胜感激!