使用OpenSSL和MSVC2017构建QT源

时间:2018-08-07 22:33:24

标签: qt visual-c++ openssl

我设法编译了openssl-1.0.2o(使用nasm-2.13.03),如下所示: https://wiki.qt.io/Building_Qt_Desktop_for_Windows_with_MSVC

但是,尝试使用以下命令进行配置时,尝试构建Qt源已经失败(在没有ssl / openssl的情况下有效):

C:/qt-everywhere-src-5.11.1/configure -platform win32-msvc2017 -prefix win32-msvc2017 -opensource -confirm-license -debug-and-release -force-debug-info -nomake examples -nomake tests -skip qtwebengine -skip qt3d -I C:\openssl-1.0.2o\out32dll -L C:\openssl-1.0.2o\out32dll -ssl -openssl

在命令行中出现以下错误:

Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.

ERROR: Feature 'openssl' was enabled, but the pre-condition '!features.securetransport && (features.openssl-linked || libs.openssl_headers)' failed.

ERROR: Feature 'ssl' was enabled, but the pre-condition 'config.winrt || features.securetransport || features.openssl' failed.

config.log显示它由于“ alloca.h”而失败

 Command line: -platform win32-msvc2017 -prefix win32-msvc -opensource -confirm-license -debug-and-release -force-debug-info -nomake examples -nomake tests -skip qtwebengine -skip qt3d -I C:\openssl-1.0.2o\out32dll -L C:\openssl-1.0.2o\out32dll -ssl -openssl
loaded result for config test config.qtbase.tests.verifyspec
+ cd /d C:\qt_build\config.tests\verifyspec && C:\qt_build\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl-1.0.2o\\out32dll" "INCLUDEPATH += C:\\openssl-1.0.2o\\out32dll" C:/Entwicklung/qt-everywhere-src-5.11.1/qtbase/config.tests/verifyspec
+ cd /d C:\qt_build\config.tests\verifyspec && set MAKEFLAGS=& jom clean && set MAKEFLAGS=& jom
> jom 1.1.2 - empower your cores
>   del verifyspec.obj
>   del verifyspec.exp verifyspec.vc.pdb verifyspec.ilk verifyspec.idb
> C:\qt_build\config.tests\verifyspec\verifyspec.exp konnte nicht gefunden werden
> jom 1.1.2 - empower your cores
>   cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdverifyspec.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -IC:\qt-everywhere-src-5.11.1\qtbase\config.tests\verifyspec -I. -IC:\openssl-1.0.2o\out32dll -IC:\qt-everywhere-src-5.11.1\qtbase\mkspecs\win32-msvc -Fo @C:\Users\msrei\AppData\Local\Temp\verifyspec.obj.5420.0.jom
> verifyspec.cpp
>   link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:verifyspec.exe @C:\Users\msrei\AppData\Local\Temp\verifyspec.exe.5420.328.jom
test config.qtbase.tests.verifyspec succeeded
loaded result for config test config.qtbase.tests.architecture
+ cd /d C:\qt_build\config.tests\arch && C:\qt_build\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl-1.0.2o\\out32dll" "INCLUDEPATH += C:\\openssl-1.0.2o\\out32dll" C:/Entwicklung/qt-everywhere-src-5.11.1/qtbase/config.tests/arch
+ cd /d C:\qt_build\config.tests\arch && set MAKEFLAGS=& jom clean && set MAKEFLAGS=& jom
> jom 1.1.2 - empower your cores
>   del arch.obj
>   del arch.exp arch.vc.pdb arch.ilk arch.idb
> C:\qt_build\config.tests\arch\arch.exp konnte nicht gefunden werden
> jom 1.1.2 - empower your cores
>   cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdarch.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -IC:\qt-everywhere-src-5.11.1\qtbase\config.tests\arch -I. -IC:\openssl-1.0.2o\out32dll -IC:\qt-everywhere-src-5.11.1\qtbase\mkspecs\win32-msvc -Fo @C:\Users\msrei\AppData\Local\Temp\arch.obj.12860.0.jom
> arch.cpp
>   link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:arch.exe @C:\Users\msrei\AppData\Local\Temp\arch.exe.12860.94.jom
Detected architecture: i386 (sse sse2)
test config.qtbase.tests.architecture gave result i386
loaded result for config test config.qtbase.tests.sse2
+ cd /d C:\qt_build\config.tests\x86_simd && C:\qt_build\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl-1.0.2o\\out32dll" "INCLUDEPATH += C:\\openssl-1.0.2o\\out32dll" "CONFIG+=add_cflags" "DEFINES+=NO_ATTRIBUTE" "SIMD=sse2" C:/Entwicklung/qt-everywhere-src-5.11.1/qtbase/config.tests/x86_simd
+ cd /d C:\qt_build\config.tests\x86_simd && set MAKEFLAGS=& jom clean && set MAKEFLAGS=& jom
> jom 1.1.2 - empower your cores
>   del main.obj
>   del x86_simd.exp x86_simd.vc.pdb x86_simd.ilk x86_simd.idb
> C:\qt_build\config.tests\x86_simd\x86_simd.exp konnte nicht gefunden werden
> jom 1.1.2 - empower your cores
>   cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -arch:SSE2 -Zi -MDd -W0 -EHsc /Fdx86_simd.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -DNO_ATTRIBUTE -DQT_COMPILER_SUPPORTS_SSE2 -IC:\qt-everywhere-src-5.11.1\qtbase\config.tests\x86_simd -I. -IC:\openssl-1.0.2o\out32dll -IC:\qt-everywhere-src-5.11.1\qtbase\mkspecs\win32-msvc -Fo @C:\Users\msrei\AppData\Local\Temp\main.obj.11032.0.jom
> main.cpp
>   link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:x86_simd.exe @C:\Users\msrei\AppData\Local\Temp\x86_simd.exe.11032.109.jom
test config.qtbase.tests.sse2 succeeded
loaded result for config test config.qtbase.tests.aesni
+ cd /d C:\qt_build\config.tests\x86_simd && C:\qt_build\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl-1.0.2o\\out32dll" "INCLUDEPATH += C:\\openssl-1.0.2o\\out32dll" "CONFIG+=add_cflags" "DEFINES+=NO_ATTRIBUTE" "SIMD=aesni" C:/Entwicklung/qt-everywhere-src-5.11.1/qtbase/config.tests/x86_simd
+ cd /d C:\qt_build\config.tests\x86_simd && set MAKEFLAGS=& jom clean && set MAKEFLAGS=& jom
> jom 1.1.2 - empower your cores
>   del main.obj
>   del x86_simd.exp x86_simd.vc.pdb x86_simd.ilk x86_simd.idb
> jom 1.1.2 - empower your cores
>   cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -arch:SSE2 -Zi -MDd -W0 -EHsc /Fdx86_simd.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -DNO_ATTRIBUTE -DQT_COMPILER_SUPPORTS_AESNI -IC:\qt-everywhere-src-5.11.1\qtbase\config.tests\x86_simd -I. -IC:\openssl-1.0.2o\out32dll -IC:\qt-everywhere-src-5.11.1\qtbase\mkspecs\win32-msvc -Fo @C:\Users\msrei\AppData\Local\Temp\main.obj.16356.0.jom
> main.cpp
>   link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:x86_simd.exe @C:\Users\msrei\AppData\Local\Temp\x86_simd.exe.16356.93.jom
test config.qtbase.tests.aesni succeeded
loaded result for config test config.qtbase.tests.alloca_h
+ cd /d C:\qt_build\config.tests\alloca_h && C:\qt_build\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl-1.0.2o\\out32dll" "INCLUDEPATH += C:\\openssl-1.0.2o\\out32dll" C:/Entwicklung/qt_build/config.tests/alloca_h
+ cd /d C:\qt_build\config.tests\alloca_h && set MAKEFLAGS=& jom clean && set MAKEFLAGS=& jom
> jom 1.1.2 - empower your cores
>   del main.obj
> C:\qt_build\config.tests\alloca_h\main.obj konnte nicht gefunden werden
>   del alloca_h.exp alloca_h.vc.pdb alloca_h.ilk alloca_h.idb
> C:\qt_build\config.tests\alloca_h\alloca_h.exp konnte nicht gefunden werden
> jom 1.1.2 - empower your cores
>   cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdalloca_h.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl-1.0.2o\out32dll -IC:\qt-everywhere-src-5.11.1\qtbase\mkspecs\win32-msvc -Fo @C:\Users\msrei\AppData\Local\Temp\main.obj.14548.0.jom
> main.cpp
> main.cpp(2): fatal error C1083: Datei (Include) kann nicht ge”ffnet werden: "alloca.h": No such file or directory
> jom: C:\qt_build\config.tests\alloca_h\Makefile [main.obj] Error 2
test config.qtbase.tests.alloca_h FAILED

3 个答案:

答案 0 :(得分:2)

它使用如下配置的openssl 1.0.2进行工作:

CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86
perl Configure VC-WIN32 --prefix=C:/openssl
nmake -f ms/ntdll.mak
nmake -f ms/ntdll.mak install

,然后进行配置:

D:/qt-everywhere-src-5.10.0/configure -platform win32-msvc2017 -prefix win32-msvc2017 -opensource -confirm-license -debug-and-release -force-debug-info -nomake examples -nomake tests -skip qtwebengine -skip qt3d -ssl -openssl-linked OPENSSL_PREFIX=C:\openssl

要在带有MSVC2017的Qt项目中使用它,请将其添加到您的项目.pro文件中

win32-msvc* {
    LIBS += -LC:/openssl/lib/ -llibeay32
    LIBS += -LC:/openssl/lib/ -lssleay32
    INCLUDEPATH += C:/openssl/include
}

答案 1 :(得分:1)

我不了解Qt 5.10,但是对于5.11.1,以下工作-打开CMD提示符并首先运行vcvarsall。

build-openssl.bat

@set SRC=openssl-1.0.2o
@if "%VSCMD_ARG_TGT_ARCH%"=="x86" (
    @set BITS=32
    @set DST=OpenSSL-Win32
    @set CONFIG=VC-WIN32
    @set SETUP=ms\do_nasm
) else if "%VSCMD_ARG_TGT_ARCH%"=="x64" (
    @set BITS=64
    @set DST=OpenSSL-Win64
    @set CONFIG=VC-WIN64A
    @set SETUP=ms\do_win64a
) else goto no_vscmd
@echo Building %SRC% for %BITS% bits.

@echo - Downloading
@perl ^
    -e "use LWP::Simple;" ^
    -e "mirror('https://www.openssl.org/source/%SRC%.tar.gz', '%SRC%.tar.gz');"

@echo - Decompressing
@if not exist %SRC%.tar.gz goto no_archive
@rmdir /S /Q %SRC% %DST% 2>NUL
@7z x -bsp2 -y %SRC%.tar.gz >NUL && ^
7z x -bsp2 -y %SRC%.tar     >NUL && ^
del %SRC%.tar
@if errorlevel 1 goto unpack_failed
@if not exist %SRC% goto no_source

@echo - Building
@pushd %SRC%
@perl Configure %CONFIG% --prefix=%~dp0..\%DST% && ^
call %SETUP% && ^
nmake -f ms\nt.mak init && ^
jom -f ms\nt.mak "CC=cl /FS" && ^
jom -f ms\nt.mak test && ^
nmake -f ms\nt.mak install || goto build_failed
@popd
@rmdir /S /Q %SRC%

@echo Build has succeeded.
@goto :eof

:no_archive
@echo Error: can't find %SRC%.tar.gz - the download has failed :(
@exit /b 1

:unpack_failed
@echo Error: unpacking has failed.
@exit /b %errorlevel%

:no_source
@echo Error: can't find %SRC%\
@exit /b 1

:build_failed
@echo The build had failed.
@popd
@exit /b 2

:no_vscmd
@echo Use vcvars-32 or vcvars-64 to set up the Visual Studio
@echo build environment first.
@exit /b 100

然后,要构建Qt 5.11.1,我使用以下配置:

-opensource
-confirm-license
-force-debug-info
-debug-and-release
-ltcg
-openssl
-qt-zlib
-qt-libpng
-qt-libjpeg
-plugin-sql-sqlite
-mp
OPENSSL_PREFIX="c:\foo\OpenSSL-Win32"
-nomake examples
-make-tool jom
-platform win32-msvc
-opengl dynamic
-no-iconv
-no-dbus

foo是您在其中运行build-openssl.bat的任何文件夹。

确保在路径中充满活力,否则您将讨厌整个过程。最新的Jom位于:http://download.qt.io/official_releases/jom/jom.zip

用于将所有工具添加到您的路径中的脚本(这样您就不必全局设置它了):

toolpaths.bat

@set V_7ZIP=%ProgramFiles%\7-Zip
@set V_PERL64=C:\Perl64
@set V_PERL32=C:\Perl
@set V_PYTHON27=C:\Python27
@set V_NASM=%ProgramFiles%\NASM
@set V_NASM32=%ProgramFiles(x86)%\NASM
@set V_SMARTGIT32=%ProgramFiles(x86)%\SmartGit
@set V_SMARTGIT=%ProgramFiles%\SmartGit
@set V_CMAKE=%ProgramFiles%\CMake
@set V_CMAKE32=%ProgramFiles(x86)%\CMake
@set V_VS2015=2015
@set V_VS2015COMNTOOLS=%VS140COMNTOOLS%
@set V_VS2017COMNTOOLS=%VS150COMNTOOLS%

@if not exist "%V_7ZIP%\7z.exe" goto no_7zip
@call :append_path "%V_7ZIP%"
@goto has_7zip
:no_7zip
@echo Warning: 7-Zip not installed. OpenSSL will not build.
:has_7zip

@if not exist "%V_PERL64%\bin" goto no_perl64
@if not exist "%V_PERL64%\site\bin" goto no_perl_site64
@call :append_path "%V_PERL64%\site\bin"
:no_perl_site64
@call :append_path "%V_PERL64%\bin"
@goto has_perl
:no_perl64

@if not exist "%V_PERL32%\bin" goto no_perl
@if not exist "%V_PERL32%\site\bin" goto no_perl_site32
@call :append_path "%V_PERL32%\site\bin"
:no_perl_site32
@call :append_path "%V_PERL32%\bin"
@goto has_perl
:no_perl
@echo Warning: Perl not installed. Qt will not build.
:has_perl

@if not exist "%V_PYTHON27%" goto no_python
@call :append_path "%V_PYTHON27%"
@goto has_python
:no_python
@echo Warning: Python 2.7 not installed. Qt will not build.
:has_python

:check_nasm
@if not exist "%V_NASM%\nasm.exe" goto check_nasm32
@call :append_path "%V_NASM%"
@goto has_nasm
:check_nasm32
@if not exist "%V_NASM32%\nasm.exe" goto no_nasm
@call :append_path "%V_NASM32%"
@goto has_nasm
:no_nasm
@echo Warning: NASM not installed. OpenSSL will not build.
:has_nasm

:check_git
@if not exist "%V_SMARTGIT%\git\bin" goto check_git32
@call :append_path "%V_SMARTGIT%\git\bin"
@goto has_git
:check_git32
@if not exist "%V_SMARTGIT32%\git\bin" goto no_git
@call :append_path "%V_SMARTGIT32%\git\bin"
@goto has_git
:no_git
@echo Warning: SmartGit not installed. Qt WebEngine might not build.
:has_git

:check_cmake
@if not exist "%V_CMAKE%\bin\cmake.exe" goto check_cmake32
@call :append_path "%V_CMAKE%\bin"
@goto has_cmake
:check_cmake32
@if not exist "%V_CMAKE32%\bin\cmake.exe" goto no_cmake
@call :append_path "%V_CMAKE32%\bin"
@goto has_cmake
:no_cmake
@echo Info: CMake not installed. This is without consequences.
:has_cmake

:: configure gyp overrides for msvs 2017 express
@if not exist "%VS150COMNTOOLS%\VsDevCmd.bat" goto no_vs2017gyp
@call :set_path V_VS2017 "%VS150COMNTOOLS%\..\.."
@echo Info: Found MSVS 2017 at "%V_VS2017%"
@set GYP_MSVS_VERSION=2017
@set GYP_MSVS_OVERRIDE_PATH=%V_VS2017%
@goto no_vs2015gyp
:no_vs2017gyp

:: configure gyp overrides for msvs 2015 express
@if not exist "%VS140COMNTOOLS%\..\IDE\WDExpress.exe" goto no_vs2015gyp
@call :set_path V_VS2015 "%VS140COMNTOOLS%\..\.."
@echo Info: Found MSVS Express 2015 at "%V_VS2015%"
@set GYP_MSVS_VERSION=2015
@set GYP_MSVS_OVERRIDE_PATH=%V_VS2015%
:no_vs2015gyp

@exit /b

:append_path
@echo %PATH%|find "%~1">nul || PATH %PATH%;%~1
@goto :eof

:set_path
@set %1=%~f2
@goto :eof

答案 2 :(得分:0)

这是我今天要解决的特定问题,并通过OpenSSL和MySQL支持构建Qt 5.11.1共享库:

将OpenSSL软件包解压缩到c:\openssl后,以下命令成功运行:

set OPENSSL_CONF=C:\openssl\ssl\openssl.cnf

configure -shared -debug-and-release -opensource -confirm-license -sql-mysql -opengl dynamic -platform win32-msvc2017 -prefix C:\Qt\qt5.11.1-msvc2017-shared -nomake tests -nomake examples -I "C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\include" -L "C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\lib" -ssl -openssl -I "C:\openssl\include" -L "C:\openssl\lib"

nmake

nmake install

我建议从Github存储库构建Qt源,这仅仅是因为如果出现问题并且需要清除构建目录,nmake clean会非常慢。要正确清理构建目录并在从git存储库进行构建时快速完成,您可以使用以下方法清除所有临时文件:

rm config.cache
git submodule foreach --recursive "git clean -dfx"

您的系统应该准备执行另一个configure