为什么编译NGINX for Windows时出现错误?

e5nqia27  于 2022-12-11  发布在  Nginx
关注(0)|答案(1)|浏览(202)

我尝试用RTMP模块编译NGINX for Windows,但总是出错。我一直遵循的指南是http://nginx.org/en/docs/howto_build_on_win32.html
我安装了以下软件:

  • 管理系统2
  • 草莓Perl(64位)
  • Visual Studio 2022(社区版)+使用C++工作负载进行桌面开发

安装MSYS 2后,我按照他们的安装后说明找到here

pacman -Syu
pacman -Su
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

我已经为PATH设置了以下系统环境变量集

C:\Strawberry\c\bin
C:\Strawberry\perl\site\bin
C:\Strawberry\perl\bin
C:\msys64\mingw64\bin

我已经将NGINX源代码下载到了'C:'驱动器上一个名为'nginx'的目录中。在这个目录中,我下载并解压缩了以下包到目录'objs/lib'中。

  • zlib-1.2.11
  • pcre2-10.39
  • openssl-1.1.1m
  • 模块-1.2.2

这将创建以下目录结构

nginx
    objs
        lib
            zlib-1.2.11
            pcre2-10.39
            openssl-1.1.1m 
            nginx-rtmp-module-1.2.2

我已通过运行Visual C目录中'vcvarsall.bat'脚本设置了Visual C环境

PS C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build> .\vcvarsall.bat amd64
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.0.5
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

在其他一些指南中,他们指示修改位于“auto\lib\openssl”的“makefile.msvc”文件原始文件

# Copyright (C) Igor Sysoev
# Copyright (C) Nginx, Inc.

all:
    cd $(OPENSSL)

    perl Configure VC-WIN32 no-shared               \
        --prefix="%cd%/openssl"                 \
        --openssldir="%cd%/openssl/ssl"             \
        $(OPENSSL_OPT)

    if exist ms\do_ms.bat (                     \
        ms\do_ms                        \
        && $(MAKE) -f ms\nt.mak                 \
        && $(MAKE) -f ms\nt.mak install             \
    ) else (                            \
        $(MAKE)                         \
        && $(MAKE) install_sw                   \
    )

修改的文件

# Copyright (C) Igor Sysoev
# Copyright (C) Nginx, Inc.

all:
    cd $(OPENSSL)

    perl Configure VC-WIN64A no-shared              \
        --prefix="%cd%/openssl"                 \
        --openssldir="%cd%/openssl/ssl"             \
        $(OPENSSL_OPT)

    if exist ms\do_win64a.bat (                     \
        ms\do_ms                        \
        && $(MAKE) -f ms\nt.mak                 \
        && $(MAKE) -f ms\nt.mak install             \
    ) else (                            \
        $(MAKE)                         \
        && $(MAKE) install_sw                   \
    )

我已使用MSYS 2 MinGW x64运行了配置脚本

auto/configure \
            --with-cc=cl \
            --with-debug \
            --builddir=objs \
            --prefix= \
            --conf-path=conf/nginx.conf \
            --pid-path=logs/nginx.pid \
            --http-log-path=logs/access.log \
            --error-log-path=logs/error.log \
            --sbin-path=nginx.exe \
            --http-client-body-temp-path=temp/client_body_temp \
            --http-proxy-temp-path=temp/proxy_temp \
            --http-fastcgi-temp-path=temp/fastcgi_temp \
            --http-scgi-temp-path=temp/scgi_temp \
            --http-uwsgi-temp-path=temp/uwsgi_temp \
            --with-cc-opt=-DFD_SETSIZE=1024 \
            --with-pcre=objs/lib/pcre2-10.39 \
            --with-zlib=objs/lib/zlib-1.2.11 \
            --with-openssl=objs/lib/openssl-1.1.1m \
            --with-openssl-opt=no-asm \
            --with-http_ssl_module \
            --add-module=objs/lib/nginx-rtmp-module-1.2.2 \
            --with-http_flv_module \
            --with-http_gzip_static_module \
            --with-http_mp4_module \
            --with-http_v2_module \
            --with-stream \
            --with-stream_ssl_module \
            --with-http_dav_module \
            --with-http_realip_module \
            --with-http_auth_request_module \
            --with-http_stub_status_module

checking for OS
 + MINGW64_NT-10.0-19044 3.3.3-341.x86_64 x86_64
 + using Microsoft Visual C++ compiler
 + cl version: 19.30
checking for MINGW64_NT-10.0-19044 specific features
configuring additional modules
adding module in objs/lib/nginx-rtmp-module-1.2.2
 + ngx_rtmp_module was configured
creating objs/Makefile

Configuration summary
  + using PCRE2 library: objs/lib/pcre2-10.39
  + using OpenSSL library: objs/lib/openssl-1.1.1m
  + using zlib library: objs/lib/zlib-1.2.11

  nginx path prefix: ""
  nginx binary file: "/nginx.exe"
  nginx modules path: "/modules"
  nginx configuration prefix: "/conf"
  nginx configuration file: "/conf/nginx.conf"
  nginx pid file: "/logs/nginx.pid"
  nginx error log file: "/logs/error.log"
  nginx http access log file: "/logs/access.log"
  nginx http client request body temporary files: "temp/client_body_temp"
  nginx http proxy temporary files: "temp/proxy_temp"
  nginx http fastcgi temporary files: "temp/fastcgi_temp"
  nginx http uwsgi temporary files: "temp/uwsgi_temp"
  nginx http scgi temporary files: "temp/scgi_temp"

最后,为了构建NGINX,我在“VS 2022的x64原生工具命令提示符”中运行了“nmake”命令,这给了我错误

C:\nginx>nmake

Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" -f objs/Makefile

Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" -f auto/lib/openssl/makefile.msvc                                 OPENSSL="objs/lib/openssl-1.1.1m" OPENSSL_OPT="no-asm"

Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cd objs/lib/openssl-1.1.1m
        perl Configure VC-WIN64A no-shared                               --prefix="%cd%/openssl"                                 --openssldir="%cd%/openssl/ssl"                         no-asm
Configuring OpenSSL version 1.1.1m (0x101010dfL) for VC-WIN64A
Using os-specific seed configuration
Creating configdata.pm
Creating makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
        if exist ms\do_win64a.bat (                                              ms\do_ms
         && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" -f ms\nt.mak                                   && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" -f ms\nt.mak install                           ) else (
                         "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe"                                                   && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" install_sw                                     )

Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        "C:\Strawberry\perl\bin\perl.exe" "-I." -Mconfigdata "util\dofile.pl"  "-omakefile" "include\crypto\bn_conf.h.in" > include\crypto\bn_conf.h
        "C:\Strawberry\perl\bin\perl.exe" "-I." -Mconfigdata "util\dofile.pl"  "-omakefile" "include\crypto\dso_conf.h.in" > include\crypto\dso_conf.h
        "C:\Strawberry\perl\bin\perl.exe" "-I." -Mconfigdata "util\dofile.pl"  "-omakefile" "include\openssl\opensslconf.h.in" > include\openssl\opensslconf.h
        "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" /                   depend && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe" /                   _all

Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        "C:\Strawberry\perl\bin\perl.exe" "util\mkbuildinf.pl" "cl /Zi /Fdossl_static.pdb /MT /Zl /Gs0 /GF /Gy /W3 /wd4090 /nologo /O2 -D"L_ENDIAN" -D"OPENSSL_PIC"" "VC-WIN64A" > crypto\buildinf.h
        cl  /Zi /Fdossl_static.pdb /MT /Zl /Gs0 /GF /Gy /W3 /wd4090 /nologo /O2 /I "." /I "include" /I "crypto" -D"L_ENDIAN" -D"OPENSSL_PIC" -D"OPENSSLDIR=\"C:\\nginx\\objs\\lib\\openssl-1.1.1m\\openssl\\ssl\"" -D"ENGINESDIR=\"C:\\nginx\\objs\\lib\\openssl-1.1.1m\\openssl\\lib\\engines-1_1\"" -D"OPENSSL_SYS_WIN32" -D"WIN32_LEAN_AND_MEAN" -D"UNICODE" -D"_UNICODE" -D"_CRT_SECURE_NO_DEPRECATE" -D"_WINSOCK_DEPRECATED_NO_WARNINGS" -D"NDEBUG"  -c /Focrypto\cversion.obj "crypto\cversion.c"
cversion.c
        cl  /Zi /Fdossl_static.pdb /MT /Zl /Gs0 /GF /Gy /W3 /wd4090 /nologo /O2 /I "." /I "include" /I "crypto" -D"L_ENDIAN" -D"OPENSSL_PIC" -D"OPENSSLDIR=\"C:\\nginx\\objs\\lib\\openssl-1.1.1m\\openssl\\ssl\"" -D"ENGINESDIR=\"C:\\nginx\\objs\\lib\\openssl-1.1.1m\\openssl\\lib\\engines-1_1\"" -D"OPENSSL_SYS_WIN32" -D"WIN32_LEAN_AND_MEAN" -D"UNICODE" -D"_UNICODE" -D"_CRT_SECURE_NO_DEPRECATE" -D"_WINSOCK_DEPRECATED_NO_WARNINGS" -D"NDEBUG"  /Zs /showIncludes "crypto\cversion.c" 2>&1 > crypto\cversion.d
        lib /nologo /out:libcrypto.lib @C:\Users\Will\AppData\Local\Temp\nm8B87.tmp
crypto\cversion.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\lib.EXE"' : return code '0x458'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'if' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.

我哪里做错了?

oxiaedzo

oxiaedzo1#

我尝试做同样的事情。我设法让构建更沿着但仍然遇到了一个问题,即OpenSSL不是从NGINX Makefile构建的,但确实使用nmake单独为x64构建了OpenSSL。以下是我的步骤:

1.我从他们的Git仓库中查看了以下三个仓库:

(starting at the nginx base folder)
mkdir objs
cd objs
mkdir lib
cd lib

git clone git clone https://github.com/openssl/openssl.git
(renamed base folder to 'openssl')

git clone https://github.com/PCRE2Project/pcre2.git
(generates pcre2-10.40 folder)

git clone https://github.com/madler/zlib.git
(generates zip-1.2.13 folder)

2.更改到openssl文件夹,并按照基本文件夹中的www.example.com文件所述设置输出环境变量NOTES-WINDOWS.md:

set PREFIX=C:\Program Files\OpenSSL
set OPENSSLDIR=C:\Program Files\Common Files\SSL
set Platform=x64

set INCLUDE="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt;

set LIB=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x64

set LIBPATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x86\store\references;C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.22621.0;C:\Program Files (x86)\Windows Kits\10\References\10.0.22621.0;C:\Windows\Microsoft.NET\Framework64\v4.0.30319

set PATH=C:/Strawberry/perl/bin;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files (x86)\HTML Help Workshop;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\;

3.运行perl配置命令

> perl Configure VC-WIN64A no-asm 

Configuring OpenSSL version 3.1.0-beta1-dev for target VC-WIN64A
Using os-specific seed configuration
Created configdata.pm
Running configdata.pm
Created makefile.in
Created makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL.md file first)      ***
***                                                                ***
**********************************************************************

4.执行nmake

(after 20 minutes of compiling)
...
cmd /C ""cl" /Zs /showIncludes  /Zi /Fdapp.pdb /Gs0 /GF /Gy /MD /W3 /wd4090 /nologo /O2 -I"apps" -I"." -I"include" -I"apps\include" -D"OPENSSL_BUILDING_OPENSSL" -D"OPENSSL_SYS_WIN32" -D"WIN32_LEAN_AND_MEAN" -D"UNICODE" -D"_UNICODE" -D"_CRT_SECURE_NO_DEPRECATE" -D"_WINSOCK_DEPRECATED_NO_WARNINGS" -D"NDEBUG"   "apps\x509.c" > apps\openssl-bin-x509.d 2>&1"
    IF EXIST apps\openssl.exe.manifest DEL /F /Q apps\openssl.exe.manifest
    "link" /nologo /debug setargv.obj /subsystem:console /opt:ref  /nologo /debug @C:\msys64\tmp\nm1758.tmp

正在创建库应用程序\openssl.lib和对象应用程序\openssl.exp IF EXIST应用程序\openssl.exe。清单“mt”-nologo -清单应用程序\openssl.exe。清单-输出资源:应用程序\openssl.exe

5.创建目标文件夹并授予自己对它们的完全控制权限

C:\Program Files\OpenSSL
C:\Program Files\Common Files\SSL

6.将OpenSSL二进制文件和SSL公用库安装到目标文件夹中

> nmake install

*** Installing runtime programs
Copying: apps//openssl.exe to C:/Program Files/OpenSSL/bin/openssl.exe
Copying: apps//openssl.pdb to C:/Program Files/OpenSSL/bin/openssl.pdb
Copying: tools//c_rehash.pl to C:/Program Files/OpenSSL/bin/c_rehash.pl
created directory `C:/Program Files/Common Files/SSL/certs'
created directory `C:/Program Files/Common Files/SSL/private'
created directory `C:/Program Files/Common Files/SSL/misc'
Copying: ./apps/openssl.cnf to C:/Program Files/Common Files/SSL/openssl.cnf.dist
Copying: ./apps/openssl.cnf to C:/Program Files/Common Files/SSL/openssl.cnf
Copying: apps//CA.pl to C:/Program Files/Common Files/SSL/misc/CA.pl
Copying: apps//tsget.pl to C:/Program Files/Common Files/SSL/misc/tsget.pl
Copying: ./apps/ct_log_list.cnf to C:/Program Files/Common Files/SSL/ct_log_list.cnf.dist
Copying: ./apps/ct_log_list.cnf to C:/Program Files/Common Files/SSL/ct_log_list.cnf
...
Copying: ./doc/html/man7/proxy-certificates.html to C:/Program Files/OpenSSL/html/man7/proxy-certificates.html
Copying: ./doc/html/man7/RAND.html to C:/Program Files/OpenSSL/html/man7/RAND.html
Copying: ./doc/html/man7/RSA-PSS.html to C:/Program Files/OpenSSL/html/man7/RSA-PSS.html
Copying: ./doc/html/man7/ssl.html to C:/Program Files/OpenSSL/html/man7/ssl.html
Copying: ./doc/html/man7/X25519.html to C:/Program Files/OpenSSL/html/man7/X25519.html
Copying: ./doc/html/man7/x509.html to C:/Program Files/OpenSSL/html/man7/x509.html

(我将在稍后编辑此部分,以添加到目前为止NGINX构建的其余部分...)

相关问题