简体   繁体   English

/../usr/local/go/src/runtime/cgo/cgo.go:34:8: 无法导入 C (cgo 预处理失败) (typecheck)

[英]/../usr/local/go/src/runtime/cgo/cgo.go:34:8: could not import C (cgo preprocessing failed) (typecheck)

Note:笔记:

  • current version of Go - 1.17.13当前版本 Go - 1.17.13
  • current version of golangci-lint - 1.45.2当前版本的 golangci-lint - 1.45.2

I am getting the same error `could not import C (cgo preprocessing failed) (typecheck) no matter which version of golangci-lint I use while I am running golangci-lint.我得到同样的错误`could not import C (cgo preprocessing failed) (typecheck) 无论我在运行 golangci-lint 时使用哪个版本的 golangci-lint。

I have seen this issue on Github: https://github.com/golangci/golangci-lint/issues/1176 where it is told to add header files (like net-snmp/net-snmp-config.h and net-snmp/mib_api.h ) to /usr/local/include. I have seen this issue on Github: https://github.com/golangci/golangci-lint/issues/1176 where it is told to add header files (like net-snmp/net-snmp-config.h and net-snmp/mib_api.h ) 到/usr/local/include.

Personally, I found this kinda files in /usr/include directory, and I copied all files with .h extension to /usr/local/include.就个人而言,我在/usr/include目录中找到了这种文件,并将所有带有.h扩展名的文件复制到/usr/local/include.

Plus, I also installed libsnmp-dev as it is said in the link above.另外,我还安装了libsnmp-dev ,正如上面链接中所说的那样。

But, I got the same error again...但是,我又遇到了同样的错误......

Any ideas to solve this issue?有什么想法可以解决这个问题吗?

I don't know why but the solution was damn easy for this issue which took my 2 days.我不知道为什么,但这个问题的解决方案非常简单,花了我 2 天的时间。

What I did was to change import "C" to import ( "C" ) in /usr/local/go/src/runtime/cgo/cgo.go file, and installing gcc.我所做的是将/usr/local/go/src/runtime/cgo/cgo.go文件中的import "C"更改为import ( "C" ) ,并安装 gcc。

That's it, guys:)就是这样,伙计们:)

PS: you are welcome to share your own answers as well because personally I didn't understand my own solution PS:也欢迎您分享您自己的答案,因为我个人不明白我自己的解决方案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在golang中通过CGO绑定openssl c绑定 - How to bind openssl c binding via CGO in golang #cgo LDFLAGS:找不到 lib 文件 - #cgo LDFLAGS: cannot find lib files cgo 在 cgo header 中写了 func 来打印数据,但没有打印任何内容 - cgo wrote func in cgo header to print data, but nothing gets printed from it 如何使用 cgo 交叉编译 Solaris? - How can I cross-compile for Solaris with cgo? GO - 无法导入包 - GO - Could not import packages 在 vscode-go 中,有没有办法为 go:generate statements 运行本地版本的工具? - In vscode-go, is there a way to run the local version of a tool for go:generate statements? 如何在运行时从 Go 代码获取 pod 外部 IP - How can I get pod external IP from Go code at runtime Trying to deploy simple go web site to google cloud with sdk - SDK source path looks to c:\users\name\...\local\Google\cloud SDK - how can I change? - Trying to deploy simple go web site to google cloud with sdk - SDK source path looks to c:\users\name\...\local\Google\cloud SDK - how can I change? 继续构建失败,无法使用 SAM CLI 为 lambda function 保存 main.go 文件的导入 - Keep getting build fail and unable to save import for main.go file for lambda function using SAM CLI 如何使用 Google Ko 构建和推送 Go 映像?你能告诉我 cloudbuild.yaml 创建映像并使用 Google 推送 go 映像的步骤吗? - How to build and push Go image using Google Ko?Could you tell me the steps for cloudbuild.yaml to create the image and push go image using Google ko?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM