Ad Widget

Collapse

[zabbix-agent2] missing libpcre.so.3 lib

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • n0tsaved
    Junior Member
    • Jul 2024
    • 3

    #1

    [zabbix-agent2] missing libpcre.so.3 lib

    Hello,

    for my environment I need to compile zabbix-agent2 7.0.3 and then distribute the binary among different servers

    Even though I'm telling the compiler to statically link binaries and libraries I get this error when running zabbix-agent2
    Code:
    /opt/zabbix_agent/sbin/zabbix_agent2: error while loading shared libraries: libpcre.so.3: cannot open shared object file: No such file or directory
    this is how I'm compiling the src
    Code:
    sh ./configure --enable-agent2 --enable-ipv6 --enable-static --enable-static-libs --prefix=/opt/zabbix-compiled --exec-prefix=/opt/zabbix-compiled
    make install

    I'm trying on debian12 amd64 right now..

    Am I missing something?
  • Answer selected by n0tsaved at 11-09-2024, 10:25.
    tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    I'm kind of surprised you didn't get errors from configure. Based upon how I read the 'configure.ac' source, the '--enable-static' and '--enable-static-libs' are supposed to be mutually exclusive and to trigger an error at configure time:

    Code:
    if test "x#static_linking" = "xyes" && test "x$static_linking_libs" = "xyes"; then
      AC_MSG_ERROR([cannot use --static and --static-libs at the same time])
    fi
    It looks like they have a typo/bug in the first branch of the test, that should be 'if test "x$static_linking" = "xyes" ...'.

    The thing to understand about zabbix_agent2 is that it's partially written in Go, so it uses the "go" toolchain to build zabbix_agent2. When you pass '--enable-static' to configure, it's currently only setting the environment variable for linking for the C toolchain (aka LDFLAGS). It's not currently setting the go equivalent. That's probably a bug in configure too, but I don't know that for certain. It could be they intended '--enable-static' to only apply to the C components. I'm not as familiar with the intricacies of building go binaries as I am building binaries and libraries from C source.

    Typically with configure there are ways to set one or more environment variables in your environment before you run configure to augment what flags are passed to various parts of the toolchain. I'm not seeing an easy way to do that with the Zabbix configure for zabbix_agent2, though.

    I was, however, able to get zabbix_agent2 to be statically linked, but I had to do it by modifying the src/go/Makefile that's generated by configure, before running "make" or "make install".

    What I did was found the macro that sets "GOLDFLAGS". It should have multiple settings already based upon what configure found, probably spread over multiple lines (mine was, anyway). What I did was added

    Code:
    -extldflags -static
    on the right side of the =, before any of the other -X or other flags that were generated by configure. That tells the Go build chain to pass '-static' to the external linker, i.e. the one that's linking to C libraries.

    Once you've made that one change, proceed with your "make" or "make install".

    Comment

    • tim.mooney
      Senior Member
      • Dec 2012
      • 1427

      #2
      I'm kind of surprised you didn't get errors from configure. Based upon how I read the 'configure.ac' source, the '--enable-static' and '--enable-static-libs' are supposed to be mutually exclusive and to trigger an error at configure time:

      Code:
      if test "x#static_linking" = "xyes" && test "x$static_linking_libs" = "xyes"; then
        AC_MSG_ERROR([cannot use --static and --static-libs at the same time])
      fi
      It looks like they have a typo/bug in the first branch of the test, that should be 'if test "x$static_linking" = "xyes" ...'.

      The thing to understand about zabbix_agent2 is that it's partially written in Go, so it uses the "go" toolchain to build zabbix_agent2. When you pass '--enable-static' to configure, it's currently only setting the environment variable for linking for the C toolchain (aka LDFLAGS). It's not currently setting the go equivalent. That's probably a bug in configure too, but I don't know that for certain. It could be they intended '--enable-static' to only apply to the C components. I'm not as familiar with the intricacies of building go binaries as I am building binaries and libraries from C source.

      Typically with configure there are ways to set one or more environment variables in your environment before you run configure to augment what flags are passed to various parts of the toolchain. I'm not seeing an easy way to do that with the Zabbix configure for zabbix_agent2, though.

      I was, however, able to get zabbix_agent2 to be statically linked, but I had to do it by modifying the src/go/Makefile that's generated by configure, before running "make" or "make install".

      What I did was found the macro that sets "GOLDFLAGS". It should have multiple settings already based upon what configure found, probably spread over multiple lines (mine was, anyway). What I did was added

      Code:
      -extldflags -static
      on the right side of the =, before any of the other -X or other flags that were generated by configure. That tells the Go build chain to pass '-static' to the external linker, i.e. the one that's linking to C libraries.

      Once you've made that one change, proceed with your "make" or "make install".

      Comment

      • n0tsaved
        Junior Member
        • Jul 2024
        • 3

        #3
        Hi tim.mooney, thanks a lot for your explanation, it was very interesting to learn about some backstories

        For any eventual viewer, what I did was insert those flags in the assignment of the GOLDFLAGS var in src/go/Makefile, and in my case turned like this

        Code:
        GOLDFLAGS = -extldflags -static -X '${PKG}.compileDate=${BUILD_DATE}' --extldflags -static -X \
            ${PKG}.compileTime=${BUILD_TIME} -extldflags -static -X ${PKG}.compileOs=${GOOS} \
            -extldflags -static -X ${PKG}.compileArch=${GOARCH}
        AGENT_GOLDFLAGS = ${GOLDFLAGS} -extldflags -static -X \
            main.confDefault=${AGENT2_CONFIG_FILE} -extldflags -static -X \
            main.applicationName=zabbix_agent2
        WEBSERVICE_GOLDFLAGS = ${GOLDFLAGS} -extldflags -static -X \
            main.applicationName=zabbix_web_service
        after this modification I compiled the src with `make install` and the generated bin started without missing libraries issues.

        Unfortunately the agent dies unexpectedly any 10 seconds and goes into a bootloop without any relevant log (even with DebugLevel=4), but I think this is another kind of problem

        Maybe I'll open another thread for that..
        In the meantime, thanks a lot

        Comment


        • tim.mooney
          tim.mooney commented
          Editing a comment
          Sorry I was a little imprecise when I said "before any of the other -X or other flags", that understandably caused some confusion.

          You only need to add '-extldflags -static' once, just before the first -X. You don't need to repeat it multiple times.

          Also, because AGENT_GOLDFLAGS and WEBSERVICE_GOLDFLAGS include the value of the GOLDFLAGS macro (that's what the "$(GOLDFLAGS)" does, it gets expanded to everything that was on the right side of the = from the GOLDFLAGS line), you don't need to modify either of those lines. Just modifying the right-hand side of the GOLDFLAGS line is enough.
      Working...