【问题标题】:Why am I getting errors compiling NGINX for Windows?为什么我在编译 NGINX for Windows 时出错?
【发布时间】:2022-12-08 10:16:30
【问题描述】:

我正在尝试使用适用于 Windows 的 RTMP 模块编译 NGINX,但我不断收到错误。我一直关注的指南是http://nginx.org/en/docs/howto_build_on_win32.html

我安装了以下软件:

  • MSYS2
  • 草莓 Perl(64 位)
  • Visual Studio 2022(社区版)+ 使用 C++ 工作负载的桌面开发

安装 MSYS2 后,我按照他们在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
  • nginx-rtmp-module-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                   \
    )

使用 MSYS2 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.

我哪里错了?

【问题讨论】:

  • 模块机器类型“x64”与目标机器类型“x86”冲突说你正在混合 32 位和 64 位。

标签: c++ windows nginx


【解决方案1】:
猜你喜欢
  • 2013-08-14
  • 1970-01-01
  • 2021-11-28
  • 2014-04-11
  • 1970-01-01
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多