How to build goncurses on os x, centos 6

huangapple go评论81阅读模式
英文:

How to build goncurses on os x, centos 6

问题

OS X、Centos 6和Debian Squeeze都自带v5.7的ncurses,但是go的包装器"goncurses"需要5.9版本。在这些平台上尝试构建它会出现以下错误:

$ go get -v code.google.com/p/goncurses
code.google.com/p/goncurses
# code.google.com/p/goncurses 
/tmp/go-build527609801/code.google.com/p/goncurses/_obj/goncurses.o: 
In function 'ncurses_is_subwin':src/code.google.com/p/goncurses/goncurses.c:71: undefined reference to `is_subwin'
/tmp/go-build527609801/code.google.com/p/goncurses/_obj/goncurses.o: 
In function 'ncurses_is_pad':src/code.google.com/p/goncurses/goncurses.c:63: undefined reference to `is_pad'

你可以使用Homebrew在OS X上安装ncurses v5.9,并在Linux上从源代码构建到/usr/local/目录下,但是在构建时如何让go使用你升级后的ncurses呢?

英文:

OS X, Centos 6 and Debian Squeeze all come with v5.7 of ncurses, but the go wrapper "goncurses" requires 5.9. Trying to build it on any of those platforms will give you an error like this:

$ go get -v code.google.com/p/goncurses
code.google.com/p/goncurses
# code.google.com/p/goncurses 
/tmp/go-build527609801/code.google.com/p/goncurses/_obj/goncurses.o: 
In function 'ncurses_is_subwin':src/code.google.com/p/goncurses/goncurses.c:71: undefined reference to `is_subwin'
/tmp/go-build527609801/code.google.com/p/goncurses/_obj/goncurses.o: 
In function 'ncurses_is_pad':src/code.google.com/p/goncurses/goncurses.c:63: undefined reference to `is_pad'

You can use homebrew to install ncurses v5.9 on os x, and build from source into /usr/local/ on linux, but how do you get go to use your upgraded ncurses when building?

答案1

得分: 2

@JimB回答了我的另一个问题https://stackoverflow.com/questions/23879205/how-to-change-lib-path-for-go-build/,他建议使用pkg-config,解决方案如下:

在CentOS 6上,你可以按照以下方式从源代码构建ncurses,这将把驱动pkg-config的.pc文件放入你自己的目录而不是/usr/lib64/pkgconfig/:

mkdir ~/local-pkg-config
PKG_CONFIG_LIBDIR=~/local-pkg-config ./configure --prefix=/usr/local/ --enable-pc-files --with-pkg-config
make && make install

在OS X上,你可以使用Homebrew安装ncurses。Homebrew通常将.pc文件与软件包一起放置,例如/usr/local/Cellar/pango/1.34.1/lib/pkgconfig/pango.pc。由于某种原因,Homebrew的ncurses没有任何.pc文件,但我成功地将CentOS的文件复制到了~/local-pkg-config并进行了修改:

@@ -1,7 +1,7 @@
-prefix=/usr/local/
+prefix=/usr/local/Cellar/ncurses/5.9/
 exec_prefix=${prefix}
 libdir=${exec_prefix}/lib
-includedir=${prefix}/include/ncurses
+includedir=${prefix}/include
 major_version=5
 version=5.9.20110404

现在,在任何平台上,你都可以开始获取goncurses包:

PKG_CONFIG_PATH=~/local-pkg-config/ go get -v code.google.com/p/goncurses
英文:

@JimB answered my other question https://stackoverflow.com/questions/23879205/how-to-change-lib-path-for-go-build/ with a suggestion to leverage pkg-config, which solution will look like this:

On CentOS 6 you can build ncurses from source like this, which will put the .pc files that drive pkg-config into your own directory instead of /usr/lib64/pkgconfig/

mkdir ~/local-pkg-config
PKG_CONFIG_LIBDIR=~/local-pkg-config ./configure --prefix=/usr/local/ --enable-pc-files --with-pkg-config
make && make install

On OS X you can install ncurses from homebrew. Homebrew usually puts .pc files along with the package, e.g. /usr/local/Cellar/pango/1.34.1/lib/pkgconfig/pango.pc. For some reason homebrew doesn't have any .pc files with its ncurses, but I successfully grabbed the CentOS ones into ~/local-pkg-config and changed them to suit:

@@ -1,7 +1,7 @@
-prefix=/usr/local/
+prefix=/usr/local/Cellar/ncurses/5.9/
 exec_prefix=${prefix}
 libdir=${exec_prefix}/lib
-includedir=${prefix}/include/ncurses
+includedir=${prefix}/include
 major_version=5
 version=5.9.20110404

Now on either platform you're set up to go get the goncurses package:

PKG_CONFIG_PATH=~/local-pkg-config/ go get -v code.google.com/p/goncurses

答案2

得分: 2

这个Gist是一个修改过的Homebrew的ncurses公式,它将.pc文件添加到了keg中。如果你使用它来安装ncurses,在调用go buildgo run之前,请使用PKG_CONFIG_PATH环境变量将pkg-config指向.pc文件。

$ export PKG_CONFIG_PATH=/usr/local/Cellar/ncurses/5.9/lib/pkgconfig
$ go run your_ncurses_program.go
英文:

This Gist is a modified ncurses formula for Homebrew that adds the .pc files to the keg. If you install ncurses with it, use the PKG_CONFIG_PATH environment variable to point pkg-config to the .pc files, before calling go build or go run.

$ export PKG_CONFIG_PATH=/usr/local/Cellar/ncurses/5.9/lib/pkgconfig
$ go run your_ncurses_program.go

huangapple
  • 本文由 发表于 2014年6月1日 07:02:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/23975235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定