教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang run时报undefined错误

golang run时报undefined错误

发布时间:2022-03-24   编辑:jiaochengji.com
教程集为您提供golang run时报undefined错误等资源,欢迎您收藏本站,我们将为您提供最新的golang run时报undefined错误资源
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"/></svg><h4>问题描述</h4>

在golang中同一个包中有两个文件,分别为main.go 和 a.go,main函数在main.go中,并且在main函数中引用了a.go中的一个结构体

运行时报错:

<pre><code class="lang-shell hljs">$ go run main.go <span class="token comment"># command-line-arguments</span> .\main.go:170:10: undefined: TestLinkTask </code></pre> <h4>
原因</h4>

go run: 会先进行编译操作,而在此处的编译它只会以这个main.go为准,导致引用其他文件出现找不到的情况
go build:不一样,它会自动查找引用文件并打包

<h4>
解决办法</h4>

方法一:
go run main.go a.go

方法二:
go run *.go

方法三:
go build

到此这篇关于“golang run时报undefined错误”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
golang run时报undefined错误
学习PHP错误与异常设置
php报错Notice: Undefined variable的解决办法
php提示Notice: Undefined variable的解决办法
PHP “Notice: Undefined variable” 和 “Notice: Undefined index”报错
PHP运行出现Notice : Use of undefined constant 的解决方法
Golang go-redis 包 client 返回 EOF
js判断undefined的方法示例
php错误Undefined variable: 如何解决
mysql 修改目录后mysqld启动报错

[关闭]
~ ~