简体   繁体   中英

Why am I getting errors compiling NGINX for Windows?

I'm trying to compile NGINX with the RTMP module for Windows but I keep getting errors. The guide I've been following is http://nginx.org/en/docs/howto_build_on_win32.html

I have the following software installed:

  • MSYS2
  • Strawberry Perl (64-bit)
  • Visual Studio 2022 (community edition) + Desktop Development with C++ workload

After installing MSYS2 I followed their post-installation instructions found here

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

I have set the following System environment variables set for PATH

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

I've downloaded the NGINX source code into a directory called 'nginx' on the 'C:' drive. Inside this directory I've then downloaded and extracted the following packages into the directories 'objs/lib'.

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

This creates the following directory structure

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

I have set Visual C environment by running 'vcvarsall.bat' script from Visual C directory

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'

In some other guides they instructed to modify the 'makefile.msvc' file found at 'auto\lib\openssl' Original file

# 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                   \
    )

Modified file

# 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                   \
    )

Using MSYS2 MinGW x64 I have ran the configure script

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"

Lastly to build NGINX I ran the 'nmake' command in 'x64 Native Tools Command Prompt for VS 2022' which gives me the errors

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.

Where am I going wrong?

I am trying to do the same thing. I managed to get the build further along, but still ran into an issue with OpenSSL not building from the NGINX Makefile, but did get OpenSSL to build for x64 seperately using nmake. Here's my steps below:

1. I checked out the following three repositories from their Git repos:

(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. Change to the openssl folder and setup the environment variables for output as discussed in the NOTES-WINDOWS.md file in the base folder:

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. Run perl Configure command

> 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. Run 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

Creating library apps\openssl.lib and object apps\openssl.exp IF EXIST apps\openssl.exe.manifest "mt" -nologo -manifest apps\openssl.exe.manifest -outputresource:apps\openssl.exe

5. Create Target Folders and Grant yourself Full Control of them

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

6. Install OpenSSL Binaries and SSL Common Libraries into Target folders

> 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

(I'll edit this later to add the rest of the NGINX build here so far...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM