网站首页 > 文章中心 > 其它

mac配置go语言

作者:小编 更新时间:2023-08-31 10:15:54 浏览量:459人看过

学习go语言,用什么IDE比较好

①.、Sublime text

由Jetbrains提供,在Java开发者中更为流行,其自带的Go插件支持语法高亮显示、代码补全、自动编译以及子库支持,这就使使用者可以很方便地将项目拆分成多个包,可以在一个单独的IDE中浏览它.它有个很好用的功能,插件使用了突出显示来显示未使用的变量或包.

目前也是一个专门针对Go的IDE了,功能很全面,具备语法高亮、自动补全、自动编译、调试、包浏览及管理.调试器在后台使用的gdb,这样可以方便地打印变量值、查看当前堆栈信息.

Netbeans内建支持了大量语言,同时具备Go插件,从而可以同创建正常项目一样,创建Go源文件,除了语法高亮以外,其Go插件并不支持其他特殊功能,如何使用IDE编译Go文件还不得而知.

最受欢迎的IDE,GoClipse插件在Eclipse中添加了IDE功能来支持Go,GoClipse提供了可配置的语法高亮显示、自动文档补全、自动编译以及最重要的实验调试支持.

mac配置go语言-图1

如何配置go语言集成开发环境 vim

①.、编译vimgdb

mkdir -p ./tmp

cd tmp

安装依赖

sudo apt-get install build-essential

sudo apt-get build-dep vim-gtk

安装

// 这里直接执行make的操作

make

sudo make install

安装vimgdb runtime

cp vimgdb_runtime ~/.vim/bundle

打开vim

:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件

添加配置.vimrc

" vimgdb插件

run macros/gdb_mappings.vim

在vim中执行gdb时,报 "Unable to read from GDB pseudo tty" 的错误,因为没有安装 gdb ,所以安装gdb

sudo apt-get install gdb

set up vundle

$ git clone ~/.vim/bundle/vundle

Configure Plugins

在.vimrc文件的开头添加下面的内容,有些不是必须的,可以注掉

set nocompatible " be iMproved, required

filetype off " required

" set the runtime path to include Vundle and initialize

set rtp+=~/.vim/bundle/vundle/

call vundle#rc()

" alternatively, pass a path where Vundle should install plugins

"let path = '~/some/path/here'

"call vundle#rc(path)

" let Vundle manage Vundle, required

Plugin 'gmarik/vundle'

" The following are examples of different formats supported.

" Keep Plugin commands between here and filetype plugin indent on.

" scripts on GitHub repos

Plugin 'tpope/vim-fugitive'

Plugin 'Lokaltog/vim-easymotion'

Plugin 'tpope/vim-rails.git'

" The sparkup vim script is in a subdirectory of this repo called vim.

" Pass the path to set the runtimepath properly.

Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" scripts from

Plugin 'FuzzyFinder'

" scripts not on GitHub

Plugin 'git://git.wincent.com/command-t.git'

" git repos on your local machine (i.e. when working on your own plugin)

Plugin ''

" ...

filetype plugin indent on " required

" To ignore plugin indent changes, instead use:

"filetype plugin on

"

" Brief help

" : PluginList - list configured plugins

" : PluginInstall(!) - install (update) plugins

" : PluginSearch(!) foo - search (or refresh cache first) for foo

" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins

" see :h vundle for more details or wiki for FAQ

" NOTE: comments after Plugin commands are not allowed.

" Put your stuff after this line

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

Config vim file .vimrc,Add content bellow in bottom of the file

" 官方的插件

" Some Linux distributions set filetype in /etc/vimrc.

" Clear filetype flags before changing runtimepath to force Vim to

" reload them.

filetype off

filetype plugin indent off

set runtimepath+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

autocmd FileType go autocmd BufWritePre Fmt

配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去,否则没有自动提示,会提示找不到模式

export GOROOT=/usr/local/go

export GOPATH=/data/app/gopath

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Set up gocode

go get -u github.com/nsf/gocode (-u flag for "update")

Configure vim in .vimrc file

Plugin 'nsf/gocode', {'rtp': 'vim/'}

写一个helloword程序,输入fmt后按C-xC-o如果能看到函数的声明展示出来,说明安装是正确的.

Set up godef

go get -v code.google.com/p/rog-go/exp/cmd/godef

go install -v code.google.com/p/rog-go/exp/cmd/godef

git clone ~/.vim/bundle/vim-godef

Bundle 'dgryski/vim-godef'

Set up gotags

go get -u github.com/jstemmer/gotags

Put the following configuration in your vimrc:

Bundle 'majutsushi/tagbar'

nmap :TagbarToggle

let g:tagbar_type_go = {

\ 'ctagstype' : 'go',

\ 'kinds' : [

\ 'p:package',

\ 'i:imports:1',

\ 'c:constants',

\ 'v:variables',

\ 't:types',

\ 'n:interfaces',

\ 'w:fields',

\ 'e:embedded',

\ 'm:methods',

\ 'r:constructor',

\ 'f:functions'

\ ],

\ 'sro' : '.',

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }

命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置.

再次按会关闭tag窗口.

PS:本地的.vimrc的配置

" 插件管理器 vundle

set nocompatible " be iMproved, required

filetype off " required

" Plugin 'tpope/vim-fugitive'

" Plugin 'Lokaltog/vim-easymotion'

" Plugin 'tpope/vim-rails.git'

" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" Plugin 'FuzzyFinder'

" Plugin 'git://git.wincent.com/command-t.git'

" Plugin ''

filetype plugin indent on " required

" filetype plugin on

" : PluginList - list configured plugins

" : PluginInstall(!)- install (update) plugins

" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins

" ********************************************************************

" 这里省略了其它不相关的插件

autocmd FileType go autocmd BufWritePre buffer Fmt

" 代码补全的插件

Bundle 'Blackrush/vim-gocode'

" 代码跳转提示

" 代码结构提示

如何在Mac源码安装Go1.5开发环境

wget

以下为网摘:

From C to Go

The gc tool chain is being converted from C to Go.

Design doc:

Go语言将使用Go代替C重写运行时环境

编译器的原因.

使用 Go 重写的好处是:

当前如果在 Goroutine 的调用堆栈中发现 C 代码,runtime 将在需要增长堆栈时回滚到老的堆栈方法.如果使用 Go 来重写

runtime,那么堆栈拷贝的方法就会更加高效

注意

这是 golang.org 分发版,也就是 gc ,而不是 gccgo

这是不同的 C 编译器,gc 工具链将使用你系统的 C 编译器来编译,gc 运行时则使用它的 C 编译器来编译

如何配置go语言开发环境

举例:我的机器:

GOPATH= c:\go;c:\go\src;F:\workspace\goSample01;

GOBIN=c:\go\bin;F:\workspace\goSample01\bin;

其中,c:\go是go的安装路径;

F:\workspace\goSample01是我写的go语言项目的工程目录;

F:\workspace\goSample01\bin是go语言项目的工程目录下的可执行文件路径;

注意:这个基本环境不包含开发工具,也不能直接编译带C代码的go程序.

/downloads/list.如果下的是压缩包,请把它解压到C盘.例如,C:\gowin-env.里面有个Console.bat是以后使用go

get的环境.举例:有个文件a.go,里面import(

"fmt"

"github.com/astaxie/beedb"

_ "github.com/ziutek/mymysql/godrv"

为了编译该a.go文件,需要启动Console.bat,然后在该命令行窗口,进入c:\go\src目录下,执行go getgithub.com/astaxie/beedb

Go get github.com/ziutek/mymysql/godrv .

配置goclipse(可选)

(如果不喜欢eclipse开发工具,请跳过这个配置.)

packagemainimport"fmt"func main(){ fmt.Printf("hello, world")}

配置gocode(可选)

如果不需要go语法辅助和eclipse里面的(按ALT+/)弹出go语言自动辅助功能,请跳过这个配置.

从开发工具这块看,go语言还不够成熟,开发工具都还不完善,有待改进.

Google有个在线运行go语言的教程(),很不错.支持在web上直接运行大部分的go程序,想了解这个教程的源代码的朋友可以通过以下方式获取.如果没兴趣,可以跳过这个步骤.

hg clone

编译带调用C代码的go文件(可选)

set GOOS=windows

set GOROOT=c:\go

set GOBIN=%GOROOT%\bin

set GOPATH=%GOROOT%;F:\workspace\goSample01;

例如:

go build -compiler gccgo test_c.go

运行调用C代码的go文件(可选)

①.、testc.go.

创建rand目录,然后在rand里面创建testc.go. 代码如下:

package rand

/*

//

#include stdio.h

*/

import "C"

func PrintHello() {

C.puts(C.CString("Hello, world\n"))

}

在rand下创建a.go.代码如下:

import "fmt"

func SayHello(name string){

fmt.Println(name)

在rand的上一级创建test_import.go.代码如下:

package main

import "./rand"

func main(){

rand.SayHello("tom")

rand.PrintHello()

go run test_import.go

在测试其它几个C代码的时候,发现windows版本的cgo还有些编译问题,同样的代码转移到苹果的XCODE下就没有问题.后来终于发现原因了,原来有些例子是unix平台下的,而在windows平台下,方法名和参数需要做调整.

例如:下面代码在windows下编译报一堆错误.

#include stdlib.h

func Random() int {

return int(C.random())

func Seed(i int) {

C.srandom(C.uint(i))

这里需要把return int(C.random()) 修改为"return int(C.rand())"

C.srandom(C.uint(i))修改为"C.srand(C.uint(i))"编译就OK了.

mac端 go语言环境配置问题

修改完环境变量,要执行一个命令应用一下

source .bash_profile

使用Mac系统,编译go语言的时候,出现这个错误,请问如何解决

以上就是土嘎嘎小编为大家整理的mac配置go语言相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章