goaccess icon indicating copy to clipboard operation
goaccess copied to clipboard

Help static compile GoAccess on Centos

Open gps3dx opened this issue 5 years ago • 13 comments

Hi, As I already posted, statically compiling GoAcess is possible on ubuntu. Problem is - that I can't seems to do that on centos 7 - which I must, as the binary I made on ubuntu is NOT working on centos.

The step i'm stuck in is the configure - I always fails with: "checking for mvaddwstr in -lncursesw... no configure: error: *** Missing development libraries for ncursesw" even though I have ncursesw installed: ncurses.x86_64 5.9-14.20130511.el7_4 @anaconda ncurses-base.noarch 5.9-14.20130511.el7_4 @anaconda ncurses-devel.x86_64 5.9-14.20130511.el7_4 @base
ncurses-libs.x86_64 5.9-14.20130511.el7_4 @anaconda ncurses-static.x86_64 5.9-14.20130511.el7_4 @base
ncurses-term.noarch 5.9-14.20130511.el7_4 @base

Here is the full config.log: https://pastebin.com/qmujMZQY

I call .configure as follows: ./configure --enable-utf8 --enable-geoip=mmdb --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --libdir=/usr/lib64 --mandir=/usr/share/man --includedir=/usr/include CFLAGS="--static" LDFLAG="-ltinfo -lncurses -libcrypto -libdl"

Can anyone please help me with such static compile ?

  • I tried to compile usng GCC 4.8.5 & 7.3.1 - no change. ** I can compile the code successfully if I don't "-static" compile it. *** I compile the latest 'development' through git. **** when I test the static binary I use root and 775 perm on the binary and 644 on the input log.

gps3dx avatar May 22 '20 15:05 gps3dx

OK - so it seems I was missing zlib-devel & zlib-static - so I managed to finally pass OP errors.

Finally I ran: CC='/usr/bin/gcc' CPP='/usr/bin/gcc -E' ./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline CFLAGS="-static" LIBS="-ltinfo -ldl"

so after I managed to produce a static compile GoAccess - I tested it on a logfile - but it crashes each time like:

[root@osboxes Downloads]# ./goaccess/goaccess localhost_access_log..2020-05-20.log --log-format='%h ^ %^[%d:%t %^] %m %r %^ %s %b %D %R %T u' --date-format=%d/%B/%Y --time-format=%T --debug-file=log.log

==29205== GoAccess 1.4 crashed by Sig 11
==29205==
==29205== VALUES AT CRASH POINT
==29205==
==29205== Line number: 46101
==29205== Offset: 46101
==29205== Invalid data: 0
==29205== Piping: 0
==29205==
==29205== STACK TRACE:
==29205==
==29205== 0 [0x407f41]
==29205== 1 [0x4611a0]
==29205==
==29205== Please report it by opening an issue on GitHub:
==29205== https://github.com/allinurl/goaccess/issues

goacess debug log shows (the 'attempting to parse color' repeating more then what you see below):

attempted to parse color module: color7:color-1
attempted to parse color attr: color7:color-1
attempted to parse color module: color7:color-1
attempted to parse color attr: color7:color141
attempted to parse color module: color7:color141
== VISITORS			0.000000
== 0			0.000000
== REQUESTS			0.000000
== 1			0.000000
== REQUESTS_STATIC			0.000000
== 2			0.000000
== NOT_FOUND			0.000000
== 3			0.000000
== HOSTS			0.000000
== 4			0.000000
== OS			0.000000
== 5			0.000000
== BROWSERS			0.000000
== 6			0.000000
== VISIT_TIMES			0.000000
== 7			0.000000
== REFERRERS			0.000000
== 9			0.000000
== REFERRING_SITES			0.000000
== 10			0.000000
== KEYPHRASES			0.000000
== 11			0.000000
== STATUS_CODES			0.000000
== 12			0.000000

I recompiled the app w/o static linking, then ran the same command to read the same log - no issues. so the crahes are limited to static linked binary. I wonder what I do wrong... I mean with 'configure' switches.

gps3dx avatar May 22 '20 19:05 gps3dx

  1. OK - I found out that even when I get that crash everytime when I static compile goaccess - I can add "> report.htm" to output html report - AND IT WORKS - IT SHOW DATA ( don't know if 100% of the input data is there though ). so crash is related most probably to the "shell" side of the app.

  2. I also tried to run the static linked compiled binary I made on lubuntu on Centos - but it seems I get the same odd unexplained crash.

gps3dx avatar May 22 '20 19:05 gps3dx

I Attach my configure output... maybe something there is problematic ?

[root@osboxes goaccess]# ./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline LDFLAGS="-static" LIBS=" -ltinfo -ldl" checking for a BSD-compatible install... /bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking whether gcc and cc understand -c and -o together... yes checking for a sed that does not truncate output... /bin/sed checking whether NLS is requested... yes checking for msgfmt... /bin/msgfmt checking for gmsgfmt... /bin/msgfmt checking for xgettext... /bin/xgettext checking for msgmerge... /bin/msgmerge checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for ld used by gcc... /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld checking if the linker (/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld) is GNU ld... yes checking for shared library run path origin... done checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for CFPreferencesCopyAppValue... no checking for CFLocaleCopyCurrent... no checking for GNU gettext in libc... yes checking whether to use NLS... yes checking where the gettext function comes from... libc checking for libintl_dgettext in -lintl... no checking for pthread_create in -lpthread... yes checking whether to build with rdynamic for GNU ld... yes checking for MMDB_open in -lmaxminddb... yes checking for mvaddwstr in -lncursesw... yes checking for library containing tputs... none required checking for ncursesw/ncurses.h... yes checking for ncurses.h... yes checking for sed... yes checking for tr... yes checking for gethostbyname in -lnsl... yes checking for socket in -lsocket... no checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking arpa/inet.h usability... yes checking arpa/inet.h presence... yes checking for arpa/inet.h... yes checking fcntl.h usability... yes checking fcntl.h presence... yes checking for fcntl.h... yes checking for inttypes.h... (cached) yes checking limits.h usability... yes checking limits.h presence... yes checking for limits.h... yes checking locale.h usability... yes checking locale.h presence... yes checking for locale.h... yes checking netdb.h usability... yes checking netdb.h presence... yes checking for netdb.h... yes checking netinet/in.h usability... yes checking netinet/in.h presence... yes checking for netinet/in.h... yes checking stddef.h usability... yes checking stddef.h presence... yes checking for stddef.h... yes checking for stdint.h... (cached) yes checking for stdlib.h... (cached) yes checking for string.h... (cached) yes checking for strings.h... (cached) yes checking sys/socket.h usability... yes checking sys/socket.h presence... yes checking for sys/socket.h... yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking for ptrdiff_t... yes checking whether struct tm is in sys/time.h or time.h... time.h checking for int64_t... yes checking for int8_t... yes checking for off_t... yes checking for size_t... yes checking for uint32_t... yes checking for uint64_t... yes checking for uint8_t... yes checking for _LARGEFILE_SOURCE value needed for large files... no checking for working memcmp... yes checking whether time.h and sys/time.h may both be included... yes checking for sys/time.h... (cached) yes checking for unistd.h... (cached) yes checking for alarm... yes checking for working mktime... yes checking whether lstat correctly handles trailing slash... yes checking whether stat accepts an empty string... no checking for strftime... yes checking for working strtod... yes checking for floor... no checking for gethostbyaddr... yes checking for gethostbyname... yes checking for gettimeofday... yes checking for malloc... yes checking for memmove... yes checking for memset... yes checking for mkfifo... yes checking for realloc... yes checking for realpath... yes checking for regcomp... yes checking for select... yes checking for setlocale... yes checking for socket... yes checking for strcasecmp... yes checking for strchr... yes checking for strcspn... yes checking for strdup... yes checking for strerror... yes checking for strncasecmp... yes checking for strpbrk... yes checking for strrchr... yes checking for strspn... yes checking for strstr... yes checking for strtol... yes checking for strtoull... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating po/Makefile.in config.status: creating src/config.h config.status: executing depfiles commands config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile

Your build configuration:

Prefix : /usr/local Package : goaccess Version : 1.4 Compiler flags : -pthread Linker flags : -lnsl -lncursesw -lmaxminddb -lpthread -ltinfo -ldl -static UTF-8 support : yes Dynamic buffer : yes Geolocation : GeoIP2 Storage method : In-Memory with On-Disk Persitance Storage TLS/SSL : no Bugs : [email protected]

gps3dx avatar May 22 '20 20:05 gps3dx

UPDATE: after installing few other packages('ostree' &'device-mapper-libs')- the configure output seems cleaner.

nonetheless, the crash still happening.

[root@osboxes goaccess]# ./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline CFLAGS="-static" LIBS=" -ltinfo -ldl" checking for a BSD-compatible install... /bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking whether gcc and cc understand -c and -o together... yes checking for a sed that does not truncate output... /bin/sed checking whether NLS is requested... yes checking for msgfmt... /bin/msgfmt checking for gmsgfmt... /bin/msgfmt checking for xgettext... /bin/xgettext checking for msgmerge... /bin/msgmerge checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for ld used by gcc... /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld checking if the linker (/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld) is GNU ld... yes checking for shared library run path origin... done checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for CFPreferencesCopyAppValue... no checking for CFLocaleCopyCurrent... no checking for GNU gettext in libc... yes checking whether to use NLS... yes checking where the gettext function comes from... libc checking for libintl_dgettext in -lintl... no checking for pthread_create in -lpthread... yes checking whether to build with rdynamic for GNU ld... yes checking for MMDB_open in -lmaxminddb... yes checking for mvaddwstr in -lncursesw... yes checking for library containing tputs... none required checking for ncursesw/ncurses.h... yes checking for ncurses.h... yes checking for sed... yes checking for tr... yes checking for gethostbyname in -lnsl... yes checking for socket in -lsocket... no checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking arpa/inet.h usability... yes checking arpa/inet.h presence... yes checking for arpa/inet.h... yes checking fcntl.h usability... yes checking fcntl.h presence... yes checking for fcntl.h... yes checking for inttypes.h... (cached) yes checking limits.h usability... yes checking limits.h presence... yes checking for limits.h... yes checking locale.h usability... yes checking locale.h presence... yes checking for locale.h... yes checking netdb.h usability... yes checking netdb.h presence... yes checking for netdb.h... yes checking netinet/in.h usability... yes checking netinet/in.h presence... yes checking for netinet/in.h... yes checking stddef.h usability... yes checking stddef.h presence... yes checking for stddef.h... yes checking for stdint.h... (cached) yes checking for stdlib.h... (cached) yes checking for string.h... (cached) yes checking for strings.h... (cached) yes checking sys/socket.h usability... yes checking sys/socket.h presence... yes checking for sys/socket.h... yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking for ptrdiff_t... yes checking whether struct tm is in sys/time.h or time.h... time.h checking for int64_t... yes checking for int8_t... yes checking for off_t... yes checking for size_t... yes checking for uint32_t... yes checking for uint64_t... yes checking for uint8_t... yes checking for _LARGEFILE_SOURCE value needed for large files... no checking for working memcmp... yes checking whether time.h and sys/time.h may both be included... yes checking for sys/time.h... (cached) yes checking for unistd.h... (cached) yes checking for alarm... yes checking for working mktime... yes checking whether lstat correctly handles trailing slash... yes checking whether stat accepts an empty string... no checking for strftime... yes checking for working strtod... yes checking for floor... no checking for gethostbyaddr... yes checking for gethostbyname... yes checking for gettimeofday... yes checking for malloc... yes checking for memmove... yes checking for memset... yes checking for mkfifo... yes checking for realloc... yes checking for realpath... yes checking for regcomp... yes checking for select... yes checking for setlocale... yes checking for socket... yes checking for strcasecmp... yes checking for strchr... yes checking for strcspn... yes checking for strdup... yes checking for strerror... yes checking for strncasecmp... yes checking for strpbrk... yes checking for strrchr... yes checking for strspn... yes checking for strstr... yes checking for strtol... yes checking for strtoull... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating po/Makefile.in config.status: creating src/config.h config.status: src/config.h is unchanged config.status: executing depfiles commands config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile

Your build configuration:

Prefix : /usr/local Package : goaccess Version : 1.4 Compiler flags : -static -pthread Linker flags : -lnsl -lncursesw -lmaxminddb -lpthread -ltinfo -ldl UTF-8 support : yes Dynamic buffer : yes Geolocation : GeoIP2 Storage method : In-Memory with On-Disk Persitance Storage TLS/SSL : no Bugs : [email protected]

gps3dx avatar May 22 '20 21:05 gps3dx

UPDATE2: So i've understand that I can't simply static link all the libraries GoAccess uses, specially the one related to glibc. ( see RedHat official doc ) somehow - don't ask me how - I managed to create a binary with chimera/complex/combination of static & dynemic libraries - but without openssl. when I use the --with-openssl flag it adds some 10+ libraries into the binary - so the gcc command is much more complicated then I though it would be.

anyway what I did ( w/o the openssl ) is: First:

./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline CFLAG="-O3" LDFLAGS="-Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -Wl,-Bdynamic -ldl -lnsl -lpthread"

then, do 'make' --> note that it shows you the 'gcc' command it used... few modification later ( as goaccess's 'configure' was not build to support static linking of any kind ):

gcc -O2 -DSYSCONFDIR="/etc" -Wall -Wextra -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Wcast-align -Wdeclaration-after-statement -Wshadow -Wold-style-definition -pthread -rdynamic -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gkhash.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/tpl.o src/ui.o src/util.o src/websocket.o src/xmalloc.o src/geoip2.o -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -Wl,-Bdynamic -lnsl -ldl -lpthread

To check the binary for its library dependency by 'ldd goaccess'

gps3dx avatar May 23 '20 09:05 gps3dx

EUREKA !! I MANAGED TO STATIC LINK ALL LIBRARIES INCLUDING OPENSSL BUT GLIBC RELATED LIBRARIES !!!

  1. I did it on Centos 7.7.1908
  2. I HAD to compile openssl 1.1.1-stable as the latest from centos 7 repository is 1.0.2 - which made issues during compilation regarding krb5 etc. Then I had to point gcc to the 1.1.1 includes & libraries folders.
  3. make sure to install: yum -y install glibc-static libstdc++-static ostree device-mapper-libs
  4. I used newer gcc ( from devtoolset-7 ) by following this guide.

##1. Install a package with repository for your system: ##On CentOS, install package centos-release-scl available in CentOS repository: $ sudo yum install centos-release-scl ##On RHEL, enable RHSCL repository for you system: $ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms ##2. Install the collection: $ sudo yum install devtoolset-7 ##3. Start using software collections: $ scl enable devtoolset-7 bash

My currently the list of dynamic libraries of my compiled binary is:

ldd goaccess linux-vdso.so.1 => (0x00007ffd0d7e1000) libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fe93ee80000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fe93ec7c000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe93ea60000) libc.so.6 => /lib64/libc.so.6 (0x00007fe93e692000) /lib64/ld-linux-x86-64.so.2 (0x00007fe93f09a000) The rest of the libraries are static linked.

My 'Configure' for goaccess is:

./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline --with-openssl CFLAG="-O3 -I/usr/local/include/openssl/" LDFLAGS="-L/usr/local/lib64 -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -Wl,-Bdynamic -lnsl -ldl -lpthread"

Then I run 'make' and re-run gcc command with:

gcc -O2 -DSYSCONFDIR="/etc" -Wall -Wextra -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Wcast-align -Wdeclaration-after-statement -Wshadow -Wold-style-definition -pthread -rdynamic -L/usr/local/lib64 -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gkhash.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/tpl.o src/ui.o src/util.o src/websocket.o src/xmalloc.o src/geoip2.o -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -Wl,-Bdynamic -lnsl -ldl -lpthread

** to compile openssl-1.1.1-stable I followed THIS GUIDE:

$ sudo git clone https://github.com/openssl/openssl.git $ sudo cd openssl $ sudo git checkout OpenSSL_1_1_1-stable $ sudo ./config $ sudo make $ sudo make test $ sudo make install

gps3dx avatar May 23 '20 13:05 gps3dx

Awesome, thanks for sharing these steps! I'll mark this as documentation.

allinurl avatar May 26 '20 01:05 allinurl

So another update: Since I need goaccess to work not only on centos 7 but 6 as well - the partially static I managed to create on centos 7, is not working on centos 6 due to glibc 1.12/15/17 compatibility issues when I tried to use it. Centos 7 is shipped with ligbc 1.17 and Centos 6 with 1.12. (source) thus, I went ahead and compiled it on centos 6.9 - but not before:

  • updating 'gettext' to v1.19 due to goaccess min requirements. I used 'Psychotic Ninja Plus' repository for that. to install it I had to remove built-in gettext with about half of OS installed packages - but I still had GUI afterwards - as I didn't reboot.
  • I still needed to compile openssl-1.1.1-stable and manually link it to gcc.
  • I used my previously reported 'configure' and 'gcc' commands to compile it.

What was interesting is that while on centos 6 (i.e glibc 1.12) I made another compile, with '-static' to have fully static binary - BUT this one worked afterward and did NOT crash !(compared to creating it on centos 7 with glibc 1.17). Not only that but due to backward compatibility of glibc on newer OSs, that fully static binary also works on Centos 7 !( after all even fully static binary that uses glibc need glibc dynamic libraries installed )

To compile fully static binary on Centos 6 I used:

./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline --with-openssl CFLAG="-O3 -I/usr/local/include/openssl/" LDFLAGS="-L/usr/local/lib64 -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -Wl,-Bdynamic -lnsl -ldl -lpthread"

( YES - i'm aware that the configure parms are for static-dynamic combo compilation - but replacing '-Wl,-Bstatic & -Wl,-Bdynamic' with just '-static' did not work. )

make rm -f goaccess gcc -O2 -DSYSCONFDIR="/etc" -Wall -Wextra -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Wcast-align -Wdeclaration-after-statement -Wshadow -Wold-style-definition -pthread -rdynamic -L/usr/local/lib64 -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gkhash.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/tpl.o src/ui.o src/util.o src/websocket.o src/xmalloc.o src/geoip2.o -static -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -lnsl -ldl -lpthread

( now, when I re-run gcc I managed to perform that replacement for '-static' I mention above )

gps3dx avatar May 26 '20 09:05 gps3dx

I Managed to statically compile GoAccess v1.52 on Centos 7.7 (excluding glibc and related libs)

I did few actions before 1. CC no longer seems to care when I passed the -L path of my compiled openssl v1.1.1 so I had to force it:

echo "/usr/local/lib64" > /etc/ld.so.conf.d/openssl.conf
ldconfig

2. I encountered "undefined reference to 'htobe16'" when compiling.

# gcc -O3 -DSYSCONFDIR=\"/etc\" -Wall -Wextra -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Wcast-align -Wdeclaration-after-statement -Wshadow -Wold-style-definition -pthread -rdynamic -L/usr/lib/x86_64-linux-gnu/ -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gkhash.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/persistence.o src/pdjson.o src/settings.o src/sort.o src/tpl.o src/ui.o src/util.o src/websocket.o src/xmalloc.o src/sha1.o   src/geoip2.o  -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -lnsl -Wl,-Bdynamic -ldl -lpthread
src/parser.o: In function 'parse_format':
parser.c:(.text+0x1b05): undefined reference to 'htobe16'
collect2: error: ld returned 1 exit status

I solved it by following this tip - therefore code change is required for src/parser.c: add in line 42 ("#define" area of code) the following: #define _BSD_SOURCE Then, make clean and do:

./configure --bindir=/usr/sbin/ --sbindir=/usr/sbin/ --sysconfdir=/etc/ --libdir=/usr/lib64/ --mandir=/usr/share/man/ --includedir=/usr/include/ --enable-utf8 --enable-geoip=mmdb --with-getline --with-openssl CFLAG="-O3 -I/usr/local/include/openssl/" LDFLAGS="-L/usr/local/lib64 -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -lnsl -Wl,-Bdynamic -ldl -lpthread"
make

gcc -O3 -DSYSCONFDIR=\"/etc\" -Wall -Wextra -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Wcast-align -Wdeclaration-after-statement -Wshadow -Wold-style-definition -pthread -rdynamic -L/usr/local/lib64 -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gkhash.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/tpl.o src/ui.o src/util.o src/websocket.o src/xmalloc.o  src/geoip2.o -Wl,-Bstatic -lncursesw -lmaxminddb -ltinfo -lssl -lcrypto -lz -lnsl -Wl,-Bdynamic -ldl -lpthread

which will compile GoAccess as (partially) static as best it can be.

gps3dx avatar Sep 23 '21 15:09 gps3dx

@gps3dx Awesome, thanks for sharing that. Would you be able to submit a PR with #define _BSD_SOURCE so I can merge it upstream?

allinurl avatar Sep 25 '21 15:09 allinurl

@allinurl - I have never created PR in Github, nonetheless I tried, I hope it's ok: https://github.com/allinurl/goaccess/commit/ee39c1a6aff777973c2ff803c430ac90feac4fdf

gps3dx avatar Sep 26 '21 09:09 gps3dx

That's interesting to see that someone else ran already into the same problem with compiling against OpenSSL 1.1.1g from EPEL 7 or generally OpenSSL 1.1.1 from a different install location.

Usually I include the PC file from the pkg-config that the OpenSSL package provides which is actually enough, for example when I build a RPM package for httpd, Dovecot or Postfix to have TLS 1.3 support. Works absolutely fine, but it didn't for GoAccess. Instead I got the same error with htobe16 like gps3dx.

I then tried to pass the OpenSSL 1.1.1 include path via --with-openssl=<path-to-openssl1.1.1-include-dir> which then surprisingly worked for me.

However, the only minor problem that persists for me now is that the argument "--with-openssl" is not listed anymore in the build configure arguments, although the binary is linked again libssl.so.1.1 and libcrypto.so.1.1.

ms217 avatar Sep 29 '21 14:09 ms217

For Ubuntu users, run the following command:

sudo apt-get install libncursesw5-dev

Source: https://stackoverflow.com/questions/26186824/how-to-install-the-ncursesw-development-libraries

abdullahdevrel avatar Jan 03 '24 09:01 abdullahdevrel