Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#1773 closed defect (invalid)

Unable to build nginx as static

Reported by: asarubbo@… Owned by:
Priority: minor Milestone:
Component: nginx-package Version: 1.15.x
Keywords: Cc:
uname -a: Linux agostino2904ortk 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: /

Description

Hello,

we are trying to build nginx static with the following code, on a clean Centos-7 x86_64:

#!/bin/bash

yum install pcre-devel gcc openssl-devel wget -y

MYWORKDIR="/tmp/nginx-compile"
MYVERSION="1.16.0"
MYFILE="nginx-"${MYVERSION}".tar.gz"

rm -fr "${MYWORKDIR}" > /dev/null 2>&1
mkdir "${MYWORKDIR}"
cd "${MYWORKDIR}"
wget -4 http://nginx.org/download/"${MYFILE}" && tar xzf "${MYFILE}" && cd nginx-"${MYVERSION}"

./configure \
        --prefix=/usr \
        --sbin-path=/usr/sbin/nginx \
        --conf-path=/etc/nginx/nginx.conf \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --pid-path=/run/nginx.pid \
        --lock-path=/run/lock/subsys/nginx \
        --http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
        --http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
        --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
        --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
        --http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
        --user=nginx \
        --group=nginx \
        --with-http_ssl_module \
        --with-http_v2_module \
        --with-threads \
        --with-cc-opt="-static -static-libgcc" \
        --with-ld-opt=""

make V=1

However the build fails at configure time with:

checking for int size ...
./configure: error: can not detect int size
make: *** No rule to make target `build', needed by `default'.  Stop.

What's wrong?
Thanks

Change History (3)

comment:1 by Maxim Dounin, 5 years ago

Resolution: invalid
Status: newclosed

Try looking into objs/autoconf.err, it should have details on what exactly compiler said. Note well that

  • most likely you'll have to proivide much more options than just -static -static-libgcc;
  • most options are to be provided for linking, not for compiling - that is, in --with-ld-opt.

And, more importantly, on Linux the result is going to be non-portable: that is, you wan't be able to use the resulting binary on other hosts, and things may be suddenly become broken on upgrades. This is due to glib limitations on static linking - for certain functions it requires the same version of the glib library to be available at runtime.

In general, it is not recommended to use static linking unless you understand what you are doing and why, and understand possible consequences.

If you have further questions, consider using support options available.

Last edited 5 years ago by Maxim Dounin (previous) (diff)

comment:2 by asarubbo@…, 5 years ago

Hello,

I did multiple tests and I realized that I copy-pasted the wrong version of the script, so I know that -static is a linked flag, it was just copied into the wrong place.
I was looking at config.log so I didn't think to look at something else, however, thanks for the hint, I was able to find the cause of the issue.

Anyway, atm, the build still fails when it tries to compile the following test:

#include <sys/types.h>
#include <unistd.h>
#include <openssl/ssl.h>

int main(void) {
    SSL_CTX_set_options(NULL, 0);
    return 0;
}

In the link parameters it is missing -lz so it fails with undefined reference to some functions provided by zlib.
Are you able to reproduce the issue?

comment:3 by Maxim Dounin, 5 years ago

As previously suggested, you'll have to provide much more options than just -static -static-libgcc, and providing appropriate static dependencies for each and every library you are compiling nginx with is among the things you'll have to do.

And, as also previously suggested, this is not something you should do unless you understand what you are doing and why, and understand possible consequences.

Note: See TracTickets for help on using tickets.