Closed GoogleCodeExporter closed 9 years ago
Please update to the latest go1 release or tip and retry. It is also possible
that your version of ncurses.h defines has_mouse() as a macro which cgo does
not play nicely with. What version of ncurses do you have installed? Can you
grep ncurses.h for has_mouse and determine if has_mouse() has been defined as a
macro?
Original comment by rthornto...@gmail.com
on 20 Jun 2012 at 2:58
go version weekly.2012-03-27 +d13076ae2f82 is the head of hg and is considered
to be ahead of go1.0.2
Well it seems that ncurses comes with mac does not contain any thing about
has_mouse.
Then I tried to compile my own libncurses with version 5.9 and then change the
curses.go as bellow
// #cgo LDFLAGS: -L/usr/local/lib -I/usr/local/include -lncurses
// #include <ncurses/ncurses.h>
Then try build again and get errors like:
form.go:336[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/form.cgo1.go:325]: cannot use w.win (type
*_Ctype_WINDOW) as type *[0]byte in function argument
form.go:342[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/form.cgo1.go:332]: cannot use w.win (type
*_Ctype_WINDOW) as type *[0]byte in function argument
form.go:348[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/form.cgo1.go:339]: cannot use
_Cfunc_form_sub(f.form) (type *[0]byte) as type *_Ctype_WINDOW in field value
menu.go:299[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/menu.cgo1.go:294]: cannot use w.win (type
*_Ctype_WINDOW) as type *[0]byte in function argument
menu.go:314[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/menu.cgo1.go:315]: cannot use sub.win (type
*_Ctype_WINDOW) as type *[0]byte in function argument
menu.go:326[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/menu.cgo1.go:329]: cannot use
_Cfunc_menu_win(m.menu) (type *[0]byte) as type *_Ctype_WINDOW in field value
panel.go:56[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/c
ode.google.com/p/goncurses/_obj/panel.cgo1.go:19]: cannot use w.win (type
*_Ctype_WINDOW) as type *[0]byte in function argument
panel.go:120[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/
code.google.com/p/goncurses/_obj/panel.cgo1.go:89]: cannot use w.win (type
*_Ctype_WINDOW) as type *[0]byte in function argument
panel.go:144[/var/folders/ps/fg9q9gq50gx_dxcfg7r8rlzw0000gn/T/go-build799170292/
code.google.com/p/goncurses/_obj/panel.cgo1.go:116]: cannot use
_Cfunc_panel_window(p.pan) (type *[0]byte) as type *_Ctype_WINDOW in field value
Original comment by idc...@gmail.com
on 20 Jun 2012 at 3:15
Since the release of go1 they no longer maintaining the 'weekly' releases.
'tip' is considered the latest post-go1.0.2:
tip 13624:b7a1cd9f1a6c
release 13231:5e806355a9e1
go1.0.2 13231:5e806355a9e1
go1.0.1 12995:2ccfd4b451d3
go1 12872:920e9d1ffd1f
weekly.2012-03-27 12869:dc5e410f0b4c
It seems that now the ncurses extensions (form, menu and panel) are causing you
issue. You you tried changing the cgo flags to reflect your new installation of
ncurses for the other libraries? I have been toying with the idea of separating
these libraries from the ncurses core rather than bundling them. This would
enforce an import of .../goncurses/form for example. This would at least let
you use the ncurses portion of the library.
After a great deal of searching, it appears that ncurses 5.7 is the most
current version of ncurses on MacOS X. In 5.8 [1], has_mouse() was added which
is why it did not work on your system. I will make a note in the wiki regarding
this issue.
[1] http://invisible-island.net/ncurses/announce-5.8.html
Original comment by rthornto...@gmail.com
on 21 Jun 2012 at 1:38
I just installed ncurses 5.9 using Homebrew and I'm still getting the
'has_mouse' undeclared error.
NOTE: I had to apply the patch from this thread to get ncurses to install
successfully:
http://lists.gnu.org/archive/html/bug-ncurses/2011-04/msg00002.html
$ brew list --versions go
go 1.0.2
$ brew list --versions ncurses
ncurses 5.9
$ go get code.google.com/p/goncurses
# code.google.com/p/goncurses
error: 'has_mouse' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
Here's a relevant grep:
$ grep -r has_mouse .
./curses.h:extern NCURSES_EXPORT(bool) has_mouse(void);
./curses.h:extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(has_mouse) (SCREEN*);
./cursesw.h:extern "C" int _nc_has_mouse(void);
./cursesw.h: bool has_mouse() const;
./ncurses.h:extern NCURSES_EXPORT(bool) has_mouse(void);
./ncurses.h:extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(has_mouse) (SCREEN*);
Original comment by gcat...@gmail.com
on 11 Jul 2012 at 4:25
I've implemented a potential fix for this issue. Forms, Menu and Panel are now
separated from the main library and will now need to be imported individually.
Second, I've created a work-around for has_mouse. Hopefully this will solve the
issue as I have no way of testing it myself.
Original comment by rthornto...@gmail.com
on 12 Jul 2012 at 3:47
Thanks for looking into this.
I'm getting a different error now:
$ go get -u code.google.com/p/goncurses
# code.google.com/p/goncurses
cc1: warnings being treated as errors
ncurses.go: In function 'ncurses_has_mouse':
ncurses.go:48: warning: implicit declaration of function 'has_mouse'
Original comment by gcat...@gmail.com
on 12 Jul 2012 at 4:28
The implicit declaration error usually indicates that a C function declaration
is missing but your grep would indicate otherwise. It's possible that this is a
clang/llvm issue, or a cgo issue on OSX, but I can't say for certain. I'll
continue to research to see what might be the issue.
Original comment by rthornto...@gmail.com
on 13 Jul 2012 at 3:27
Thanks! Let me know if there's anything other info about my system that would
be helpful.
Also, I'll try to apply the post-5.9 patches to my ncurses library and see if
that makes a difference.
Original comment by gcat...@gmail.com
on 13 Jul 2012 at 3:31
Can you try writing an ncurses program in C to verify has_mouse() works
natively?
Original comment by rthornto...@gmail.com
on 13 Jul 2012 at 3:33
I copied the hello world example, compiled, and ran it without error:
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html
But my C foo is weak, and I'm guessing it linked against the system version of
ncurses (5.7.20081102). How do I force it to link against 5.9?
Original comment by gcat...@gmail.com
on 13 Jul 2012 at 3:39
Looks like '-include' is what I needed:
$ gcc -include /usr/local/Cellar/ncurses/5.9/include/ncurses/ncurses.h hello.c
Undefined symbols for architecture x86_64:
"_initscr", referenced from:
_main in ccDlKAbl.o
"_printw", referenced from:
_main in ccDlKAbl.o
"_stdscr", referenced from:
_main in ccDlKAbl.o
"_wrefresh", referenced from:
_main in ccDlKAbl.o
"_wgetch", referenced from:
_main in ccDlKAbl.o
"_endwin", referenced from:
_main in ccDlKAbl.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I haven't applied the various ncurses patches yet. Doing that next.
Original comment by gcat...@gmail.com
on 13 Jul 2012 at 3:47
I applied the following rollup patch:
ftp://invisible-island.net/ncurses/5.9/ncurses-5.9-20120616-patch.sh.bz2
It didn't address the has_mouse issue. :(
Original comment by gcat...@gmail.com
on 13 Jul 2012 at 4:10
Similar output from clang:
$ clang -I/usr/local/Cellar/ncurses/5.9/include/ncurses/ncurses.h hello.c
Undefined symbols for architecture x86_64:
"_initscr", referenced from:
_main in hello-13MyQM.o
"_printw", referenced from:
_main in hello-13MyQM.o
"_stdscr", referenced from:
_main in hello-13MyQM.o
"_wrefresh", referenced from:
_main in hello-13MyQM.o
"_wgetch", referenced from:
_main in hello-13MyQM.o
"_endwin", referenced from:
_main in hello-13MyQM.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I assume this means I'm mixing 32 and 64 bit code, but I'm not sure what to do
about it.
Original comment by gcat...@gmail.com
on 13 Jul 2012 at 4:55
Run the following on that hello world example, if it successfully linked and
compiled, (assumes binary is named 'a.out'; if you used -o flag replace a.out
with whatever you named the binary) in order to see what library was linked
against it:
$ldd a.out | grep curses
It will be something akin to /usr/lib/libncursesw.so.5 but this is likely a
symbolic link. Use:
$ls -l /usr/lib/libncursesw.so.5
To find out what it links to. If the result is libncursesw.so.5.9 then it's
linking against your updated library.
I would also be interested to know the output of:
$pkg-config ncurses --modversion
...if any. I don't know if OSX has pkg-config installed or if homebrew installs
a .pc file for ncurses. If the reported version is 5.9 then I may be able to
leverage pkg-config to at least ensure the correct library is used.
Original comment by rthornto...@gmail.com
on 13 Jul 2012 at 5:34
There's no ldd in OS X, but there is otool.
The hello world that works is linked against the version of ncurses that comes
with OS X, not with the Homebrew version:
$ gcc hello.c -lncurses
$ otool -L a.out |grep curses
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
ls -l /usr/lib/libncurses.5.4.dylib
-rwxr-xr-x 1 root wheel 546K Oct 8 2011 /usr/lib/libncurses.5.4.dylib*
pkg-config is in OS X, but not helpful in this case:
$ pkg-config ncurses --modversion
Package ncurses was not found in the pkg-config search path.
Perhaps you should add the directory containing `ncurses.pc'
to the PKG_CONFIG_PATH environment variable
No package 'ncurses' found
I can't figure out how to link hello.c against the Homebrew version of ncurses.
I keep getting "Undefined symbols for architecture" errors.
Original comment by gcat...@gmail.com
on 13 Jul 2012 at 2:57
To link against a specific library, simply include the library in the
objects/sources to compile. Example:
$gcc -o hello hello.c /usr/lib/libncurses.so.5.9
Judging by the fact that your system is linking against the 5.7 ncurses
previously installed on your system, go/cgo will too. This is probably why
has_mouse() is still undefined/unresolved. If this is the case and you can
successfully compile and run the C code, the simplest way to make the change
permanent is to alter the libncurses.so symlink to point to the 5.9 version.
Please take this advice at your own risk. If this works, I highly recommend you
contact the homebrew people to see if they can create a fix for this.
Please let me know the result so I can either close this issue or continue to
research another solution.
Original comment by rthornto...@gmail.com
on 16 Jul 2012 at 2:32
Sorry for the delay, I wasn't notified (or perhaps didn't see a notification)
of your last comment.
I was able to get the example to successfully compile with the latest version
of ncurses by specifying the path as you advised:
$ gcc -o hello hello.c /usr/local/lib/libncurses.dylib
$ otool -L hello
hello:
/usr/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
After modifying the libncurses symlinks in /usr/lib to point /usr/local/lib. I
was again able to successfully compile against the latest ncurses, this time
without specifying the path:
$ gcc -o hello hello.c -lncurses
$ otool -L hello
hello:
/usr/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
However, "go get" still wasn't working:
$ go get -u code.google.com/p/goncurses
# code.google.com/p/goncurses
cc1: warnings being treated as errors
ncurses.go: In function 'ncurses_has_mouse':
ncurses.go:20: warning: implicit declaration of function 'has_mouse'
So I cloned this repo (http://code.google.com/r/gcatlin-goncurses/), added an
absolute path to the #include (http://goo.gl/6htPe), pushed it, then ran go get
on the cloned repo:
$ go get -u code.google.com/p/gcatlin-goncurses
There was no output that time. A simple test (which may be worth adding to your
home page) confirmed that it installed successfully:
---
package main
import goncurses "code.google.com/p/gcatlin-goncurses"
func main() {
w, _ := goncurses.Init()
defer goncurses.End()
w.Print("Hello World! Press any key to quit.")
w.Refresh()
w.GetChar()
}
---
Clearly, my solution is not tenable, but it may be worth documenting as a
work-around.
Original comment by gcat...@gmail.com
on 23 Jul 2012 at 3:01
I have just pushed an alternative fix that should allow goncurses to build on
ncurses 5.7. I will also update the wiki to include your work-around, or
something similar, since it would be preferable if users linked against version
5.9.
Original comment by rthornto...@gmail.com
on 24 Jul 2012 at 1:56
Wiki has been updated and the issue is considered closed.
Original comment by rthornto...@gmail.com
on 25 Jul 2012 at 1:21
First, let me express my appreciation for working with me on trying to resolve
this issue. Thank you!
Second and unfortunately, it is still not working, although it appears to be
getting closer:
$ go get -u code.google.com/p/goncurses
# code.google.com/p/goncurses
window.go:250[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:272]: w.win._cury undefined
(type *[0]byte has no field or method _cury)
window.go:250[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:272]: w.win._curx undefined
(type *[0]byte has no field or method _curx)
window.go:263[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:287]: w.win._clear undefined
(type *[0]byte has no field or method _clear)
window.go:268[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:293]: w.win._use_keypad
undefined (type *[0]byte has no field or method _use_keypad)
window.go:285[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:312]: w.win._maxy undefined
(type *[0]byte has no field or method _maxy)
window.go:285[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:312]: w.win._maxx undefined
(type *[0]byte has no field or method _maxx)
window.go:322[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build629847214
/code.google.com/p/goncurses/_obj/window.cgo1.go:354]: w.win._parent undefined
(type *[0]byte has no field or method _parent)
Original comment by gcat...@gmail.com
on 25 Jul 2012 at 3:05
[deleted comment]
I have pushed some changes which should fix these additional issues. Let me
know if this works!
Original comment by rthornto...@gmail.com
on 27 Jul 2012 at 1:49
Almost there.
$ go get -u code.google.com/p/goncurses
# code.google.com/p/goncurses
window.go:326[/var/folders/s5/fg_990bd4qn035mcbx8r41vm0000gn/T/go-build763017235
/code.google.com/p/goncurses/_obj/window.cgo1.go:359]: w.win._parent undefined
(type *[0]byte has no field or method _parent)
Original comment by gcat...@gmail.com
on 27 Jul 2012 at 4:02
Pushed a fix for this. Hopefully this will be the final issue.
If this works, you could consider trying to enable one of the extensions, panel
would probably be the best choice, by modifying panel_posix.go and adding
'darwin' to the list of platforms in the +build section. If it fails, please
open a separate issue.
Original comment by rthornto...@gmail.com
on 28 Jul 2012 at 9:25
It works! Thanks for your persistence.
I'll look into enabling the extensions.
Original comment by gcat...@gmail.com
on 30 Jul 2012 at 3:40
Original comment by rthornto...@gmail.com
on 30 Jul 2012 at 2:12
Original issue reported on code.google.com by
idc...@gmail.com
on 19 Jun 2012 at 3:10