在Windows上安装了MinGW,但在运行go时仍然出现错误。

huangapple go评论65阅读模式
英文:

MinGW installed in windows but still throwing error in while go run

问题

我最初在运行Go语言服务器代码时遇到了错误,错误出现在代码的导入行中:

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/confluentinc/confluent-kafka-go/kafka"
)

错误提示要检查%PATH%变量中是否存在可执行的gcc:

# github.com/confluentinc/confluent-kafka-go/kafka 
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

为了解决这个问题,我安装了MinGW gcc编译器并将其添加到了路径中,在终端中进行了检查:

g++ (tdm64-1) 10.3.0
版权所有 (C) 2020 Free Software Foundation, Inc.
这是自由软件;请参阅源代码以了解复制条件。没有任何保证;甚至没有适用于特定目的的适应性保证。

这仍然导致相同的错误,请问有人可以告诉我如何在Windows 10中解决这个问题。

编辑:

通过重新启动终端解决了这个问题。问题在于即使重新启动了Visual Studio Code中的终端,路径变量仍未设置,所以我只能使用普通的PowerShell来运行脚本。

英文:

I was initially facing the error during running a server code for go lang and the error in the import lines of the code

import (
"encoding/json"
"fmt"
"log"

"github.com/confluentinc/confluent-kafka-go/kafka")

The error it was thrown was to check for executable gcc in the %PATH% variable

# github.com/confluentinc/confluent-kafka-go/kafka 
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

To rectify this i have installed MinGW gcc compiler and include in the path
Checked it in the terminal

g++ (tdm64-1) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This throwing the same error can anyone please tell me how to rectify this in windows 10.

EDIT:

This was resolved by restarting the terminal
The issue was even after restarting the terminal in Visual code the path variable was not set so just used plain old powershell to run the script.

答案1

得分: 0

这个问题通过重新启动终端解决了。即使在 Visual Studio Code 中重新启动终端后,路径变量仍未设置,所以只需使用普通的 PowerShell 运行脚本即可。

英文:

This was resolved by restarting the terminal The issue was even after restarting the terminal in Visual code the path variable was not set so just used plain old powershell to run the script.

huangapple
  • 本文由 发表于 2022年8月13日 02:09:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/73338225.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定