go.mod:5: unknown directive: toolchain

Go语言toolchain指令版本兼容问题解决
该文章已生成可运行项目,

Go语言版本较旧,而项目使用了较新版本的Go语言特性。错误信息"unknown directive: toolchain"表明go.mod文件中使用了"toolchain"指令,这是在Go 1.21版本中新引入的特性,但您当前安装的Go版本不支持这个指令。

解决方法:

  1. 更新Go版本(推荐):

    # 添加Go语言官方仓库
    sudo add-apt-repository ppa:longsleep/golang-backports
    sudo apt update
    
    # 安装最新版Go
    sudo apt install golang-go
    
    # 检查版本
    go version
    
  2. 修改go.mod文件
    打开项目中的go.mod文件,找到并删除或注释掉包含"toolchain"的行:

    nano go.mod
    # 找到类似于 "toolchain go1.21.0" 的行并删除
    
  3. 使用-mod=mod标志

    go build -mod=mod -o wx_video_download main.go
    
  4. 使用环境变量忽略未知指令

    GODEBUG=gomoderrors=0 go build -o wx_video_download main.go
    

Ubuntu 22.04默认提供的Go版本通常是1.18,而项目可能使用了Go 1.21+的功能。更新到最新版本是最干净的解决方案,这样可以避免其他可能的兼容性问题。

本文章已经生成可运行项目
building [html]: targets for 9 source files that are out of date updating environment: [new config] 9 added, 0 changed, 0 removed reading sources... [100%] peripheral-device D:\tplearning\内部培训\课题\资料\doc\api\source\channel.rst:18: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_channel :members: D:\tplearning\内部培训\课题\资料\doc\api\source\channel.rst:21: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: osdp_write_fn_t D:\tplearning\内部培训\课题\资料\doc\api\source\channel.rst:23: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: osdp_read_fn_t D:\tplearning\内部培训\课题\资料\doc\api\source\channel.rst:25: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: osdp_flush_fn_t D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:30: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_led_params :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:33: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_led :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:39: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_buzzer :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:45: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_text :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:51: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_output :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:57: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_comset :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:63: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_keyset :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:69: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_mfg :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:75: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_cmd_file_tx :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:81: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_status_report :members: D:\tplearning\内部培训\课题\资料\doc\api\source\command-structure.rst:84: ERROR: Unknown directive type "doxygenenum". .. doxygenenum:: osdp_status_report_type D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:16: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: osdp_t D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:18: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_setup D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:20: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_refresh D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:22: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_teardown D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:30: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: cp_event_callback_t D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:32: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_set_event_callback D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:46: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_submit_command D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:48: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_flush_commands D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:58: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_pd_cap :members: D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:61: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_get_capability D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:66: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_get_pd_id D:\tplearning\内部培训\课题\资料\doc\api\source\control-panel.rst:68: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_cp_modify_flag D:\tplearning\内部培训\课题\资料\doc\api\source\event-structure.rst:26: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_event_keypress :members: D:\tplearning\内部培训\课题\资料\doc\api\source\event-structure.rst:32: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_event_cardread :members: D:\tplearning\内部培训\课题\资料\doc\api\source\event-structure.rst:38: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_event_mfgrep :members: D:\tplearning\内部培训\课题\资料\doc\api\source\event-structure.rst:44: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_status_report :members: D:\tplearning\内部培训\课题\资料\doc\api\source\event-structure.rst:47: ERROR: Unknown directive type "doxygenenum". .. doxygenenum:: osdp_status_report_type D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:7: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_logger_init D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:9: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_get_version D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:11: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_get_source_info D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:16: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_get_status_mask D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:18: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_get_sc_status_mask D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:24: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_file_ops :members: D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:27: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_file_register_ops D:\tplearning\内部培训\课题\资料\doc\api\source\miscellaneous.rst:29: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_get_file_tx_status D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:8: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_pd_info_t :members: D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:18: ERROR: Unknown directive type "doxygendefine". .. doxygendefine:: OSDP_FLAG_ENFORCE_SECURE D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:20: ERROR: Unknown directive type "doxygendefine". .. doxygendefine:: OSDP_FLAG_INSTALL_MODE D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:22: ERROR: Unknown directive type "doxygendefine". .. doxygendefine:: OSDP_FLAG_IGN_UNSOLICITED D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:24: ERROR: Unknown directive type "doxygendefine". .. doxygendefine:: OSDP_FLAG_ENABLE_NOTIFICATION D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:26: ERROR: Unknown directive type "doxygendefine". .. doxygendefine:: OSDP_FLAG_CAPTURE_PACKETS D:\tplearning\内部培训\课题\资料\doc\api\source\pd-info.rst:28: ERROR: Unknown directive type "doxygendefine". .. doxygendefine:: OSDP_FLAG_ALLOW_EMPTY_ENCRYPTED_DATA_BLOCK D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:12: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: osdp_t D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:14: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_setup D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:16: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_refresh D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:18: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_teardown D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:24: ERROR: Unknown directive type "doxygenstruct". .. doxygenstruct:: osdp_pd_cap :members: D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:27: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_set_capabilities D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:32: ERROR: Unknown directive type "doxygentypedef". .. doxygentypedef:: pd_command_callback_t D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:34: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_set_command_callback D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:48: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_submit_event D:\tplearning\内部培训\课题\资料\doc\api\source\peripheral-device.rst:50: ERROR: Unknown directive type "doxygenfunction". .. doxygenfunction:: osdp_pd_flush_events looking for now-outdated files... none found pickling environment... done checking consistency... D:\tplearning\内部培训\课题\资料\doc\api\source\index.rst: WARNING: document isn't included in any toctree done preparing documents... done copying assets... copying static files... done copying extra files... done copying assets: done writing output... [100%] peripheral-device generating indices... genindex done writing additional pages... search done dumping search index in English (code: en)... done dumping object inventory... done build succeeded, 58 warnings. The HTML pages are in build\html.
09-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值