登录
首页 >  Golang >  Go问答

使用 golang 依赖模块的特定版本

来源:stackoverflow

时间:2024-04-20 17:06:35 256浏览 收藏

哈喽!今天心血来潮给大家带来了《使用 golang 依赖模块的特定版本》,想必大家应该对Golang都不陌生吧,那么阅读本文就都不会很困难,以下内容主要涉及到,若是你正在学习Golang,千万别错过这篇文章~希望能帮助到你!

问题内容

我正在尝试从 github 链接构建 postfix-exporter 代码。 它依赖于 go.mod 文件 github.com/coreos/go-systemd/v22 v22.0.0 中提到的 go-systemd 包。 我在 go.mod 文件中看到,提到的包版本是 v22.0.0. 但是当我针对此路径运行 go get -u 时,它开始下载 go-systemd 的最新版本( v22.2.0),该版本在最新提交中存在问题并导致编译失败。 出现的错误是

github.com/coreos/go-systemd/[email protected]/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/[email protected]/sdjournal/journal.go:27: pkg/mod/github.com/coreos/go-systemd/[email protected]/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])

我想知道,如果这不是方法或者我缺少遵守 go.mod 中提到的依赖包版本所需的某些选项,如何编译任何依赖项模块的特定版本

提前非常感谢,请原谅我的 golang 知识。


解决方案


不要使用 -u-u 的目的是让 go 尝试将你升级到最新的次要版本或补丁版本:

-u 标志指示 get 更新提供依赖项的模块 在命令行上命名的软件包以使用较新的次要版本或补丁 可用时发布。

如果你只是想安装依赖项,请使用 go get

我试图为 centos7 构建 podman 并发现此错误,注意到 _sd_array_static 未定义,所以我只是进行了搜索在google中找到了这个头文件:https://code.woboq.org/qt5/include/systemd/_sd-common.h.html。 另外,通过在我的 docker 中搜索这个文件,我发现了这个非常旧的文件:/usr/include/systemd/_sd-common.h,所以我决定修改它并添加该定义:

/*-*- 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

瞧,一切正常了。 tl;dr,可能您必须更新 systemd 软件包或至少更新 systemd c 库。

本篇关于《使用 golang 依赖模块的特定版本》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>