go run footer.go 的时候呢, go会依次去GOPATH 和GOROOT设置的对应路径下面找对应的包(目录和文件)

找的时候呢, 会在GoPATH 和GOROOT对应的目录后面再加一层路径 "/src/"哦

---------------------------------------------------------------------------------------------

https://stackoverflow.com/questions/32110524/go-run-cannot-find-package

I have a sample project setup based on this article.

This is my directory structure:

goloang/
└── fooproject
   └── src
   ├── foo
   │   └── foo.go
   └── fooer
   └── fooer.go

I have set the GOTPATH

$ echo $GOPATH
/Users/Bharat/Dev/golang/fooproject

I am trying to run foor.go but I get a cannot find package error even though it exists in the location referenced by GOPATH i.e. in src/foo.

This is how I am running it:

$ pwd
/Users/Bharat/Dev/goloang/fooproject/src/fooer $ go run fooer.go
fooer.go:4:3: cannot find package "foo" in any of:
/usr/local/go/src/foo (from $GOROOT)
/Users/Bharat/Dev/golang/fooproject/src/foo (from $GOPATH)

These are the file contents.

src/foo/foo.go:

package foo

import (
"fmt"
) func Bar() {
fmt.Println("bar")
}

src/fooer/fooer.go:

package main

import (
"foo"
) func main() {
foo.Bar()
}

I get the same error when I try to do go build fooer.go.

Where am I going wrong with the project structure?

-------------------------------------------------------------------------

3down voteaccepted

That might be because of a typo:

goloang
instead of
golang

You have:

$ echo $GOPATH
/Users/Bharat/Dev/golang/fooproject
^^^^^^
$ pwd
/Users/Bharat/Dev/goloang/fooproject/src/fooer
^^^^^^^
answered Aug 20 '15 at 6:00
VonC

696k22521002319
 
    
goloang doesn't look like the correct spelling. – VonC Aug 20 '15 at 6:04
    
Aah!! My eyes seem bad. It was really a stupid mistake. Another pair of eyes looking at it was helpful! It works now. – Bharat Aug 20 '15 at 6:06
    
@Bharat 11PM in SF... I understand ;) I've been there many times. – VonC Aug 20 '15 at 6:07 

golang 的GOPATH设置的问题的更多相关文章

  1. golang,liteide设置 windows7(64)

    1.安转go的环境,exe安装包 2.下载liteide27.2.1 3.打开liteide开始开发,在里面添加gopath,无法读取windows里面的gopath设置,不知道什么原因,以管理员运行 ...

  2. golang中GOPATH的简单理解

    1.为什么要配置GOPATH 配置GOPATH的用意是为了方便项目的部署和构建,以及可以直接使用go get 命令下载第三方的包到自己的项目的src下和相关的执行文件bin目录,和中间文件pkg sr ...

  3. golang之交叉编译设置

    俺的环境,os x,目的,生成64位linux的elf文件 直接下载osx的包就可以,不需要特意去下载源码包,我的go目录是~/golang/go cd ~/golang/go/srcGOOS=lin ...

  4. GOPATH设置

    go help gopath查看gopath的原文帮助信息 go env查看gopath的配置 GOPATH与工作空间 前面我们在安装Go的时候看到需要设置GOPATH变量,Go从1.1版本到1.7必 ...

  5. windows下gopath设置

    下载了go语言的安装包, 然后安装, 装完了需要设置三个地方: 1. 在windows的PATH变量中添加go的可执行文件所在的目录: PATH=C:\Go\bin;其他设置; 2. 设置 GOROO ...

  6. Golang 项目 GOPATH 总结

    查看GOPATH go env 项目里执行:go  get  github/winyh/XXX 命令时, 包会下载到 GOPATH第一个目录下的src文件夹 项目里引入依赖的时候会自动到GOPATH里 ...

  7. golang mysql 如何设置最大连接数和最大空闲连接数

    本文介绍golang 中连接MySQL时,如何设置最大连接数和最大空闲连接数. 关于最大连接数和最大空闲连接数,是定义在golang标准库中database/sql的. 文中例子连接MySQL用的SQ ...

  8. golang网络通信超时设置

    网络通信中,为了防止长时间无响应的情况,经常会用到网络连接超时.读写超时的设置. 本文结合例子简介golang的连接超时和读写超时设置. 1.超时设置 1.1 连接超时 func DialTimeou ...

  9. 【Golang】vscode 设置 go 开发环境

    步骤 1. 始 Golang 语言开发选择一款合适的编辑器,能加速你敲字的灵感,这里推荐微软的 Visual Studio Code,简称 vscode. 2. 安装 go 插件 首先需要安装 go ...

随机推荐

  1. 倒计时和div幻灯片

    倒计时从10秒开始,10秒之后,同意按钮可以使用. 设置一个区域背景,三张照片滚动显示,左右按钮可以下一张上一张,如果点击了左右按钮就不再自动滚动.

  2. Jquery 全选、反选问题的记录

    <div id="list"> <ul id="choseList" > <li><input type=" ...

  3. Apache Calcite项目简介

    文章导读: 什么是Calcite? Calcite的主要功能? 如何快速使用Calcite? 什么是Calcite Apache Calcite是一个动态数据管理框架,它具备很多典型数据库管理系统的功 ...

  4. C#知识点-反射

    一.开发环境 操作系统:Win7 编译器:VS2010 .net版本:.net4.0 二.项目结构 三.开发流程 0.编写实体类 namespace ReflectDemo { public clas ...

  5. data和string类型之间的相互转换

    package main; import java.text.SimpleDateFormat;import java.util.Date; import freemarker.core.ParseE ...

  6. UIPickerView 多级联动

    UIPickerView的多级联动问题有些地方需要注意,其实多级联动并不难...楼主因为项目需要又没法使用网上的第三方,所以最近写了一个省市区多级联动,还是手写代码好!! 为了演示效果,我会多定义几个 ...

  7. Laravel5.1学习笔记21 EloquentORM 集合

    Eloquent: Collections Introduction Available Methods Custom Collections Introduction All multi-resul ...

  8. 微信关于网页授权access_token和普通access_token的区别

    微信官网网址:https://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html#.E9.99.84.EF.BC.9A.E6. ...

  9. Codeforces_750_C_(二分查找)

    C. New Year and Rating time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  10. 梦想CAD控件COM接口文字样式

    增加文字样式 用户可以增加文字样式到数据库,并设置其字体等属性,具体实现c#代码如下: private void CreateText() { MxDrawApplication app = new ...