您的位置:首页 > Web前端

fedora环境交叉编译transmission1.83的QT工程

2016-01-12 19:32 525 查看
研究了很多天如何在Fedara环境下,交叉编译windows下运行的transmission,把过程记录下来,希望能帮到有需要的人。

环境使用的是fedora23,为什么? 在源的安装和更新方面比较智能,能省去不少的时间,其次它的tab功能也足够强大,好处多多。闲言少叙,上教程:

一、在fedora23命令行下,安装必要的环境:

dnf install mingw32-gcc mingw32-gtk2 mingw32-crossreport mingw32-nsiswrapper wine

dnf install mingw32-curl

dnf install mingw32-qt

dnf install mingw32-gcc-c++

fedora23下的mingw32命令gcc为i686-w64-mingw32-gcc,  gcc+命令是i686-w64-mingw32-g++,一定要根据当前fedora版本明确。

二、在https://trac.transmissionbt.com/wiki/BuildingTransmissionQtWindows上下在transmission对应的补丁

这里用的transmission1.8.3,使用的是transmission-1.83-Qt-build.diff,打好代码的补丁

curl "http://trac.transmissionbt.com/wiki/BuildingTransmissionQtWindows/transmission-1.83-Qt-build.diff?format=txt" -O transmission-1.83-Qt-build.diff

patch -p1 < transmission-1.83-Qt-build.diff

三、运行transmission-1.83的configure生成相应makefile, 生成libtransmission.a库和第三方库

1) mingw32-configure --disable-nls --disable-largefile --disable-cli --disable-gtk

脚本根据系统环境,检查编译环境,最后会显示当前的gcc++编译为i686-w64-mingw32-g++,环境检查通过以后就得到相应的Makefile,我们这里的脚本同时还生成了Qt/Makefile, Makefile.Release, Makefile.Debug. 以及第三方库的相应makefile。

这里我们要对transmission-1.83根目录下的makefile进行编辑,查找所有gcc,gcc+,ar相应的定义位置,检查是否为正确的编译器,是否为正确mingw32的库路径。如果不正确应该全部替换成名mingw32对应的命令,例如我这里的CXX = i686-w64-mingw32-g++,CXXCPP = i686-w64-mingw32-g++ -E 有错误将直接导致结果错误。

2) make CFLAGS="-pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -mms-bitfields -DSTATICLIB"

直行make编译,可能会出现的错误:

1. minissdpc.c:20:3: error: unknown type name 'uint16_t' 例如这样的,先检查是否有相关的typdef或者宏定义,如果没有自己定义typedef unsigned int uint16_t;

2. evdns.c:2340:5: error: conflicting types for 'evdns_resolve_reverse_ipv6',我发现evdns.c中有struct in6_addr 的相关定义,果断去掉。

3. 相关win32的修改,可通过transmission-1.83-Qt-build.diff做比较

4. 如果修改以后,编译不过,也需要进行make clean再重新编译,总之要反复进行试验。

3) make install

四、进入QT目录,编译QT工程:

1)导入变量,设置以后要使用echo检查是否设置成功。

export QMAKESPEC=fedora-win32-cross

export PKG_CONFIG_LIBDIR=/usr/i686-pc-mingw32/sys-root/mingw/lib/pkgconfig

2)确定fedora23下的fedora-win32-cross编译环境

通过rpm -qi qt得到我们安装的是4.8.7版本,找到qt4的安装路径,我们可以看到在 usr/lib/qt4/mkspecs路径下的所有编译环境脚本,唯独没有关于fedora win32 cross编译的脚本,因此需要手动建立相关文件。

首先建立fedora-win32-cross文件夹,对应的上面的export QMAKESPEC的指向路径。在这个文件夹下手动添加两个文件qmake.conf qplatformdefs.h

要将对应的gcc,gcc+,ar修改为当前系统环境的中的相关编译器环境。建立好以后,那么qmake的使用本地的编译环境就配置好了。

3)执行 qmake-qt4 -win32 QT_LIBINFIX=4 qtr.pro 脚本,会显示“-win32 is deprecated. ”不必理会。

4)执行 make clean && make debug:

1、编译错误

details.cc:101:70:   required from here /usr/i686-w64-mingw32/sys-root/mingw/include/QtCore/qglobal.h:2515:15: error: 'dynamic_cast_will_always_fail_because_rtti_is_disabled' is not a member of  'const PeerItem*'

显然是我们的makefile脚本定义 QT_NO_DYNAMIC_CAST 宏导致的,打开makefile,可以读出,具体编译的makefile分为 Makefile.Release Makefile.Debug, 我们打开这两个Makefile,在DEFINES 定义行中,去掉“-DQT_NO_DYNAMIC_CAST”, 在CFLAGS和CXXFLAGS的定义中去掉所有“-fno-rtti”运行时的定义。

2、连接错误

_imp__select@20、_imp__ntohs@4等是有关socket的库链接问题,在Makefile.Debug/Makefile.Release的LIBS定义中加入 -lws2_32

deflateInit_、deflate、deflateReset等是有关zlib的库链接问题,在Makefile.Debug/Makefile.Release的LIBS定义中加入 -lz

破除所有错误编译后会在qt/debug目录下得到qtr.exe,release版本只需执行make clean && make release. exe文件生成了! 

五、安装qtr.exe

在QT目录下运行:INSTALL_ROOT=/usr/i686-w64-mingw32/sys-root/mingw make release-install

将qtr.exe安装在/usr/i686-w64-mingw32/sys-root/mingw/bin/qtr.exe

六、软链接QT UI相关库

ln -s /usr/i686-w64-mingw32/sys-root/mingw/bin/QtCore4.dll /usr/i686-w64-mingw32/sys-root/mingw/bin/qtcore4.dll

ln -s /usr/i686-w64-mingw32/sys-root/mingw/bin/QtGui4.dll /usr/i686-w64-mingw32/sys-root/mingw/bin/qtgui4.dll

ln -s /usr/i686-w64-mingw32/sys-root/mingw/bin/QtNetwork4.dll /usr/i686-w64-mingw32/sys-root/mingw/bin/qtnetwork4.dll

七、打包

nsiswrapper --run --name "QtTransmission" --outfile QtTransmission-1.83_installer.exe --installdir 'C:\Program Files\Transmission' /usr/i686-w64-mingw32/sys-root/mingw/bin/qtr.exe

将必要文件压缩打入包内:

File: "QtCore4.dll" [compress] 1231210/3088463 bytes

File: "qtcore4.dll" [compress] 0/3088463 bytes

File: "QtGui4.dll" [compress] 4482498/10898004 bytes

File: "qtgui4.dll" [compress] 0/10898004 bytes

File: "QtNetwork4.dll" [compress] 572158/1556671 bytes

File: "qtnetwork4.dll" [compress] 0/1556671 bytes

File: "iconv.dll" [compress] 13929/29902 bytes

File: "libcrypto-10.dll" [compress] 626298/1464832 bytes

File: "libcurl-4.dll" [compress] 189583/404602 bytes

File: "libgcc_s_sjlj-1.dll" [compress] 142059/475851 bytes

File: "libidn-11.dll" [compress] 65533/207061 bytes

File: "libintl-8.dll" [compress] 49488/104347 bytes

File: "libpng16-16.dll" [compress] 106605/208677 bytes

File: "libssh2-1.dll" [compress] 66475/152902 bytes

File: "libssl-10.dll" [compress] 156724/358912 bytes

File: "libstdc++-6.dll" [compress] 3392404/11583580 bytes

File: "libwinpthread-1.dll" [compress] 22866/51484 bytes

File: "qtr.exe" [compress] 440264/1163776 bytes

File: "zlib1.dll" [compress] 45960/85026 bytes

得到QtTransmission-1.83_installer.exe

仓促间难免有误,欢迎指正。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息