[ZBXNEXT-5609] Investigate Agent2 compilation on Windows Created: 2019 Oct 21  Updated: 2024 Apr 10  Resolved: 2020 Jun 04

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Agent (G)
Affects Version/s: 4.4.3
Fix Version/s: 4.4.4rc1, 5.0.0alpha1, 5.0 (plan)

Type: Change Request Priority: Trivial
Reporter: Andris Zeila Assignee: Andris Zeila
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Team: Team A
Sprint: Sprint 57 (Oct 2019), Sprint 58 (Nov 2019), Sprint 59 (Dec 2019), Sprint 60 (Jan 2020), Sprint 61 (Feb 2020), Sprint 62 (Mar 2020), Sprint 63 (Apr 2020), Sprint 64 (May 2020)
Story Points: 5

 Description   

There are several issues that should be checked/solved to build agent2 on windows:

  1. not in all places linux specific code is properly put into linux specific files/protected with +build option. This is already being improved in DEV-1323
  2. cGO on Windows requires gcc compatible compiler, while we are using Microsoft C compiler for Windows builds.
  3. the shared C code must compile with the gcc compatible compiler, so it can be linked together.
  4. link to OpenSSL dll for encryption support

First we must focus on (2). Might be easier to check with small prototype. Then we can start working on (3) by expanding prototype to use C/GO linking approach used in agent2. After linking issues are solved we can start working on agent C code compilation for linking with agent2.



 Comments   
Comment by Andris Zeila [ 2019 Nov 05 ]

Build environment setup

mingw64

  1. Download mingw. Look for x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.7z
    1. need SJLJ (set jump/long jump) exception handling and windows threads
  2. Extract and move to c:\mingw
  3. Setup environmental variable
    @echo off
    set PATH=%PATH%;c:\bin\mingw\bin
    cmd
    

When compiling use windows prompt rather than MSYS terminal provided by mingw

PCRE

The following instructions will compile and install 64 bit pcre libraries at c:\dev\pcre and 32 bit libraries at c:\dev\pcre32:

  1. download 8.x sources from ftp://ftp.pcre.org/pub/pcre/ and extract
  2. open cmd and navigate to the extracted sources

    Build 64bit PCRE

  3. delete old configuration/cache if exists:
    1. del CMakeCache.txt
    2. rmdir /q /s CMakeFiles
  4. cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS="-O2 -g" -DCMAKE_CXX_FLAGS="-O2 -g" -DCMAKE_INSTALL_PREFIX=c:\dev\pcre
  5. mingw32-make clean
  6. mingw32-make install

    Build 32bit PCRE

  7. mingw32-make clean
  8. del CMakeCache.txt
  9. rmdir /q /s CMakeFiles
  10. cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS="-m32 -O2 -g" -DCMAKE_CXX_FLAGS="-m32 -O2 -g" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-mi386pe" -DCMAKE_INSTALL_PREFIX=c:\dev\pcre32
  11. mingw32-make install

OpenSSL

Donwload 32 and 64 bit builds from https://bintray.com/vszakats/generic/openssl/1.1.1d, extract into c:\dev\openssl32 and c:\dev\openssl directories accordingly. After it remove extracted *.dll.a (dll call wrapper libraries) as mingw prioritizes them before static libraries.

Agent2 build process

32 bit

1. open mingw environment (windows command prompt) and navigate to build/mingw directory in Zabbix source tree
2. mingw32-make clean
3. mingw32-make ARCH=x86 PCRE=c:\dev\pcre32 OPENSSL=c:\dev\openssl32

64 bit

1. open mingw environment (windows command prompt) and navigate to build/mingw directory in Zabbix source tree
2. mingw32-make clean
3. mingw32-make PCRE=c:\dev\pcre OPENSSL=c:\dev\openssl

Notes

32 and 64 bit versions can be built on 64 bit platform, but only 32 bit version can be built on 32 bit platform. When working on 32 bit platform the steps are the same as 64bit build steps on 64 bit platform.

Comment by Andris Zeila [ 2019 Dec 02 ]

Released ZBXNEXT-5609 in:

  • pre-4.4.4rc1 014f43c2a0
  • pre-5.0.0alpha1 3b74170245

Note that currently the number of supported checks is quite minimalistic:

  • agent.*
  • log*
  • eventlog*
  • system.run

The main goal was to add build support, additional checks will be added in future.

Comment by Andris Zeila [ 2019 Dec 02 ]

(15) Does not build with older OpenSSL versions
RESOLVED in development branch feature/ZBXNEXT-5609-4.4 (pull request)
vso REOPENED, fails on windows with OpenSSL enabled

c /MT /Gy /W3 /c /D _WINDOWS /D _CONSOLE /D UNICODE  /D _UNICODE /D HAVE_WINLDAP_H /D HAVE_ASSERT_H /D ZABBIX_SERVICE /D "_VC80_UPGRADE=0x0600" /D HAVE_IPV6 /TC /DPCRE_STATIC /DHAVE_OPENSSL /DHAVE_OPENSSL_WITH_PSK
tls.c
..\..\..\src\libs\zbxcrypto\tls.c(413): warning C4013: 'ERR_get_error_line_data' undefined; assuming extern returning int
..\..\..\src\libs\zbxcrypto\tls.c(415): warning C4013: 'ERR_error_string_n' undefined; assuming extern returning int
..\..\..\src\libs\zbxcrypto\tls.c(419): error C2065: 'ERR_TXT_STRING': undeclared identifier
..\..\..\src\libs\zbxcrypto\tls.c(3232): warning C4013: 'RAND_status' undefined; assuming extern returning int
..\..\..\src\libs\zbxcrypto\tls.c(4327): warning C4244: 'function': conversion from 'ZBX_SOCKET' to 'int', possible loss of data
..\..\..\src\libs\zbxcrypto\tls.c(4378): warning C4013: 'ERR_peek_error' undefined; assuming extern returning int
..\..\..\src\libs\zbxcrypto\tls.c(5080): warning C4244: 'function': conversion from 'ZBX_SOCKET' to 'int', possible loss of data
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\cl.exe"' : return code '0x2'
Stop.

wiper: RESOLVED in 933bcc474

vso CLOSED
wiper: REOPENED & RESOLVED in 8fbf6dfc3

vso CLOSED

Comment by Andris Zeila [ 2019 Dec 04 ]

Released ZBXNEXT-5609 in:

  • pre-4.4.4rc1 eca7009488
  • pre-5.0.0alpha1 135111a0fd
Comment by Marina Generalova [ 2020 May 11 ]

Documentation updated:

Generated at Fri May 02 17:12:04 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.