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. 实用and常用shell命令汇编

    很久没写blog了,基本都在用 github和笔记.现在将一些常用的shell并且很使用的shell用法分享一下: 分行读取,切割,计数: cat product.txt | while read l ...

  2. Matlab2014的下载和安装激活过程

    Matlab2014的下载和安装过程 转载自csdn  https://blog.csdn.net/hp910315/article/details/70197149 1 下载Matlab2014,下 ...

  3. Windows sever 2003 IIS6.0 搭建DVWA

    DVWA 环境: Windows Sever 2003 IIS 6.0+MYSQL+PHP5.4+FASFCGI 详细教程: http://files.cnblogs.com/files/yyx001 ...

  4. Qt 5.8.3 部署/添加 Crypto++第三方库(5.6.5版本)

    首先,Qt没有封装加解密算法库(其实有个哈希函数的函数).介于OpenSSL函数封装不友好,以及先前爆发的心脏滴血漏洞广受诟病,我们考虑在C++上使用一种新的,并且封装友好的,OOAD程度更高的加解密 ...

  5. 【转】非常好的Java反射例子

    转自 http://www.douban.com/note/306848299/ 原文: 1.Java反射的概念 反射含义:可以获取正在运行的Java对象. 2.Java反射的功能 1)可以判断运行时 ...

  6. Codeforces_766_C_(dp)

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Xamarin View获取属性的绑定信息

    public static Binding GetBinding( BindableObject self, BindableProperty property) { var methodInfo = ...

  8. [转]Linux中进程内存与cgroup内存的统计

    From: http://hustcat.github.io/about/ Linux中进程内存与cgroup内存的统计 在Linux内核,对于进程的内存使用与Cgroup的内存使用统计有一些相同和不 ...

  9. 25款css动画库

    http://www.swiper.com.cn/usage/animate/index.html   //swiper https://cssanimation.io/ http://ianlunn ...

  10. [Luogu] P1407 [国家集训队]稳定婚姻

    题目描述 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有关. 25岁的姗姗和男友谈恋爱半年就结婚,结婚不到 ...