简体   繁体   中英

Using a particular version for golang dependency module

I'm trying to build postfix-exporter code from the github link . It has a dependency on the go-systemd package as mentioned in go.mod file github.com/coreos/go-systemd/v22 v22.0.0 . I see in the go.mod file, the mentioned version for the package is v22.0.0. But when I run go get -u for this path, it starts downloading the latest version ( v22.2.0 ) of go-systemd which has an issue in the latest commit and causing failure to compile. The error coming in that is

github.com/coreos/go-systemd/v22@v22.2.0/sdjournal/journal.go:313:60: error: '_SD_ARRAY_STATIC' undeclared here (not in a function) // my_sd_id128_to_string(void *f, sd_id128_t boot_id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]) ^ In file included from /usr/include/systemd/sd-journal.h:31:0, from pkg/mod/github.com/coreos/go-systemd/v22@v22.2.0/sdjournal/journal.go:27: pkg/mod/github.com/coreos/go-systemd/v22@v22.2.0/sdjournal/journal.go:313:77: error: expected ']' before numeric constant // my_sd_id128_to_string(void *f, sd_id128_t boot_id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX])

I want to know, how to compile for a specific version of any dependency module if this is not the way or I'm missing some option required to honor the version of dependency packages mentioned in go.mod

Thanks very much in advance and please pardon my golang knowledge.

Don't use -u . The purpose of -u is to allow Go to try to upgrade you to the latest minor or patch version:

The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available.

If you're just trying to install dependencies, use go get .

I was trying to build podman for Centos7 and found this error, noticed that _SD_ARRAY_STATIC was not defined, so I just did a search in google and found this header file: https://code.woboq.org/qt5/include/systemd/_sd-common.h.html . Also, by doing a search of this file in my docker I found this very old one: /usr/include/systemd/_sd-common.h , so I just decided to modify it and add that definition:

/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/

#ifndef foosdcommonhfoo
#define foosdcommonhfoo

/***
  This file is part of systemd.

  Copyright 2013 Lennart Poettering
...
...
#ifndef _SD_END_DECLARATIONS
#  ifdef __cplusplus
#    define _SD_END_DECLARATIONS                                \
        }                                                       \
        struct __useless_struct_to_allow_trailing_semicolon__
#  else
#    define _SD_END_DECLARATIONS                                \
        struct __useless_struct_to_allow_trailing_semicolon__
#  endif
#endif

#ifndef _SD_ARRAY_STATIC
#  if __STDC_VERSION__ >= 199901L
#    define _SD_ARRAY_STATIC static
#  else
#    define _SD_ARRAY_STATIC
#  endif
#endif

#endif

And voila, got it working. TL;DR, probably you have to update systemd package or at least the systemd C library.

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