From: Uno on 27 Jun 2010 04:56 I've been trying to work a capability with curses, and I don't see what I'm missing here: $ gcc -Wall -Wextra p3.c -o out /tmp/cc2Zv1sK.o: In function `tty_break': p3.c:(.text+0x7): undefined reference to `initscr' p3.c:(.text+0xc): undefined reference to `cbreak' /tmp/cc2Zv1sK.o: In function `tty_getchar': p3.c:(.text+0x1e): undefined reference to `stdscr' p3.c:(.text+0x26): undefined reference to `wgetch' /tmp/cc2Zv1sK.o: In function `tty_fix': p3.c:(.text+0x33): undefined reference to `endwin' collect2: ld returned 1 exit status $ cat p3.c #include <stdio.h> #include <curses.h> int tty_break() { initscr(); cbreak(); return 0; } int tty_getchar() { return getch(); } int tty_fix() { endwin(); return 0; } int main(void) { int i; if(tty_break() != 0) return 1; for(i = 0; i < 10; i++) printf(" = %d\n", tty_getchar()); tty_fix(); return 0; } // gcc -Wall -Wextra p3.c -o out $ Background here: http://www.c-faq.com/osdep/cbreak.html Anyways, fishing for tips, -- Uno
From: Ike Naar on 27 Jun 2010 05:04 In article <88oi1kFoshU1(a)mid.individual.net>, Uno <merrilljensen(a)q.com> wrote: >I've been trying to work a capability with curses, and I don't see what >I'm missing here: > >$ gcc -Wall -Wextra p3.c -o out >/tmp/cc2Zv1sK.o: In function `tty_break': >p3.c:(.text+0x7): undefined reference to `initscr' >p3.c:(.text+0xc): undefined reference to `cbreak' >/tmp/cc2Zv1sK.o: In function `tty_getchar': >p3.c:(.text+0x1e): undefined reference to `stdscr' >p3.c:(.text+0x26): undefined reference to `wgetch' >/tmp/cc2Zv1sK.o: In function `tty_fix': >p3.c:(.text+0x33): undefined reference to `endwin' >collect2: ld returned 1 exit status You must link the curses library to your program. Try gcc -Wall -Wextra p3.c -o out -lcurses
From: Ersek, Laszlo on 27 Jun 2010 09:28 On Sun, 27 Jun 2010, Uno wrote: > $ gcc -Wall -Wextra p3.c -o out > /tmp/cc2Zv1sK.o: In function `tty_break': > p3.c:(.text+0x7): undefined reference to `initscr' -l curses > #include <stdio.h> > #include <curses.h> Prepend at least #define _XOPEN_SOURCE 500 and if you use ENHANCED CURSES interfaces as well, then additionally #define _XOPEN_SOURCE_EXTENDED 1 http://www.opengroup.org/onlinepubs/007908775/xcurses/implement.html AIUI, there's no more recent formal standard than SUSv2 defining CURSES. With "at least" in "prepend at least" above I'm trying to say that on any given platform you might be able to find a platform-specific feature test macro too, whose effect implies that of _XOPEN_SOURCE and co. For example, _GNU_SOURCE with glibc. lacos
From: Uno on 27 Jun 2010 17:51 Ersek, Laszlo wrote: > Prepend at least > > #define _XOPEN_SOURCE 500 > > and if you use ENHANCED CURSES interfaces as well, then additionally > > #define _XOPEN_SOURCE_EXTENDED 1 > > > http://www.opengroup.org/onlinepubs/007908775/xcurses/implement.html > > AIUI, there's no more recent formal standard than SUSv2 defining CURSES. > > With "at least" in "prepend at least" above I'm trying to say that on > any given platform you might be able to find a platform-specific feature > test macro too, whose effect implies that of _XOPEN_SOURCE and co. For > example, _GNU_SOURCE with glibc. $ gcc -Wall -Wextra -lcurses p3.c -o out $ cat p3.c #define _XOPEN_SOURCE 500 //#define _XOPEN_SOURCE_EXTENDED 1 #include <stdio.h> #include <curses.h> int tty_break() { initscr(); cbreak(); return 0; } int tty_getchar() { return getch(); } int tty_fix() { endwin(); return 0; } int main(void) { int i; if(tty_break() != 0) return 1; for(i = 0; i < 10; i++) printf(" = %d\n", tty_getchar()); tty_fix(); return 0; } // gcc -Wall -Wextra -lcurses p3.c -o out $ How can I tell whether these macros are doing anything for me? -- Uno
From: Uno on 27 Jun 2010 17:52
Ike Naar wrote: > You must link the curses library to your program. Try > gcc -Wall -Wextra p3.c -o out -lcurses That's it, thx Ike. -- Uno |