在 debian64 中编译 Qt 5 失败

compilation of Qt 5 fails under make in debian64

我尝试使用 openSsl 配置制作 qt 5.4.1,但在制作过程中遇到了一些错误。

我配置如下:

OPENSSL_LIBS='-L/usr/local/ssl/lib -lssl -lcrypto' ./configure -prefix $PWD/qtbase -opensource -debug-and-release -nomake tests -openssl-linked -I/usr/local/ssl/include -L/usr/local/ssl/lib

然后是make.

输出的最后 10 行是:

/usr/bin/ld: /usr/local/ssl/lib/libssl.a(s2_srvr.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/ssl/lib/libssl.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[3]: *** [../../lib/libQt5Network.so.5.4.1] Error 1
make[3]: Leaving directory `/mnt/l/software/qt-everywhere-opensource-src-5.4.1/qtbase/src/network'
make[2]: *** [sub-network-make_first] Error 2
make[2]: Leaving directory `/mnt/l/software/qt-everywhere-opensource-src-5.4.1/qtbase/src'
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory `/mnt/l/software/qt-everywhere-opensource-src-5.4.1/qtbase'
make: *** [module-qtbase-make_first] Error 2

要link一个静态库变成x86_64上的共享库,静态库需要用-fPIC编译。您现在可以使用 -fPIC 设置手动构建 OpenSSL,但这会有点麻烦。

我建议使用 -openssl 而不是 -openssl-linked 配置 Qt。然后 SSL 不会在编译时被 linked,而是在运行时动态加载 (dlopen)。这是在 Qt 中处理 OpenSSL 的常用方法,也是因为 OpenSSL 和 GPL 许可证之间的不兼容。