Click to See Complete Forum and Search --> : curses program won't compile


monkeyboi
09-13-2002, 03:41 AM
i try to compile this C code and it always give me errors

here is the code:
---------------------------
#include <stdio.h>
#include <stdarg.h>
#include <curses.h>

#define max_string 1024

static struct {
WINDOW *mainwin;
WINDOW *text;
WINDOW *cmd;
} mw;

static void initialize (void);
static void printwin (const char *fmt, ...);

void main ()
{
char buf[128];

initialize ();

while (1) {
wgetnstr (mw.cmd, buf, sizeof (buf));
printwin ("%s\n", buf);
}
}

static void printwin (const char *fmt, ...)
{
static int cur_line;

va_list ap;
char buf[max_string];

memset (buf, 0, sizeof (buf));

va_start (ap, fmt);
vsnprintf (buf, max_string, fmt, ap);
va_end (ap);

wprintw (mw.text, buf);
wrefresh (mw.text);

wclear (mw.cmd);
wrefresh (mw.cmd);

cur_line++;

if (cur_line==22) {
scroll(mw.text);
cur_line=0;
}
}

static void initialize (void)
{
initscr ();
cbreak ();

if (LINES < 5 || COLS < 10) {
fprintf (stderr, "no way\n");
exit (1);
}

mw.mainwin = newwin (LINES - 1, 0, 0, 0);
mw.text = newwin (LINES - 3, COLS - 2, 1, 1);
mw.cmd = newwin (1, 0, LINES - 1, 0);

scrollok(mw.text, TRUE);


box (mw.mainwin, ACS_VLINE, ACS_HLINE);

wrefresh (stdscr);
wrefresh (mw.mainwin);
wrefresh (mw.text);
wrefresh (mw.cmd);
doupdate ();
}

------------------
this is the command i use to compile
gcc curses-test.c -o curses-test -lncurse
i also tried
gcc curses-test.c -o curses-test -lcurse

and here is the errors i got

---------------------

ncurses-test.c: In function `main':
ncurses-test.c:17: warning: return type of `main' is not `int'
/tmp/ccSwWkgx.o: In function `main':
/tmp/ccSwWkgx.o(.text+0x27): undefined reference to `wgetnstr'
/tmp/ccSwWkgx.o: In function `printwin':
/tmp/ccSwWkgx.o(.text+0x9d): undefined reference to `wprintw'
/tmp/ccSwWkgx.o(.text+0xae): undefined reference to `wrefresh'
/tmp/ccSwWkgx.o(.text+0xbf): undefined reference to `wclear'
/tmp/ccSwWkgx.o(.text+0xd0): undefined reference to `wrefresh'
/tmp/ccSwWkgx.o(.text+0xf2): undefined reference to `wscrl'
/tmp/ccSwWkgx.o: In function `initialize':
/tmp/ccSwWkgx.o(.text+0x10f): undefined reference to `initscr'
/tmp/ccSwWkgx.o(.text+0x114): undefined reference to `cbreak'
/tmp/ccSwWkgx.o(.text+0x11a): undefined reference to `LINES'
/tmp/ccSwWkgx.o(.text+0x123): undefined reference to `COLS'
/tmp/ccSwWkgx.o(.text+0x15a): undefined reference to `LINES'
/tmp/ccSwWkgx.o(.text+0x161): undefined reference to `newwin'
/tmp/ccSwWkgx.o(.text+0x174): undefined reference to `COLS'
/tmp/ccSwWkgx.o(.text+0x17d): undefined reference to `LINES'
/tmp/ccSwWkgx.o(.text+0x186): undefined reference to `newwin'
/tmp/ccSwWkgx.o(.text+0x197): undefined reference to `LINES'
/tmp/ccSwWkgx.o(.text+0x1a2): undefined reference to `newwin'
/tmp/ccSwWkgx.o(.text+0x1bc): undefined reference to `scrollok'
/tmp/ccSwWkgx.o(.text+0x1cf): undefined reference to `acs_map'
/tmp/ccSwWkgx.o(.text+0x1d5): undefined reference to `acs_map'
/tmp/ccSwWkgx.o(.text+0x1db): undefined reference to `acs_map'
/tmp/ccSwWkgx.o(.text+0x1e1): undefined reference to `acs_map'
/tmp/ccSwWkgx.o(.text+0x1ed): undefined reference to `wborder'
/tmp/ccSwWkgx.o(.text+0x1f8): undefined reference to `stdscr'
/tmp/ccSwWkgx.o(.text+0x1fe): undefined reference to `wrefresh'
/tmp/ccSwWkgx.o(.text+0x20f): undefined reference to `wrefresh'
/tmp/ccSwWkgx.o(.text+0x220): undefined reference to `wrefresh'
/tmp/ccSwWkgx.o(.text+0x231): undefined reference to `wrefresh'
/tmp/ccSwWkgx.o(.text+0x239): undefined reference to `doupdate'
collect2: ld returned 1 exit status

-------------

and yes i got my ncurses and curses library installed... i did it like 5 times using slackware ugradepkg....

btw i run slackware 8.1

thx in advance

l01yuk
09-13-2002, 04:06 AM
gcc curses-test.c -o curses-test -lncurse
Just a quick one to check, did you do what you typed or did you do

gcc curses-test.c -o curses-test -lncurses

(note s on the end).

Ok, so can you check that there is a /usr/include/curses.h file. It should be there if the install was successful. Also, check that the lib file is in /usr/lib/libncurses*

Also, make the return type of main int. It is good practice.

monkeyboi
09-13-2002, 08:39 PM
this what i get when i try to take out the "s"..


ncurses-test.c: In function `main':
ncurses-test.c:17: warning: return type of `main' is not `int'
/usr/i386-slackware-linux/bin/ld: cannot find -lncurse
collect2: ld returned 1 exit status

i check the /usr/include/ folder, ncurses.h and curses.h is there...

then i check the /usr/lib/ folder
i found the following files
libncurses.a, libncurses_g.a, libncurses.p.a, libncurses.o

binaryDigit
09-14-2002, 01:27 PM
Don't take out the 's'

-lncurses

monkeyboi
09-15-2002, 07:10 AM
that too... same error
here is what i tried..
-lncurse
-lncurses
-lcurse
-lcurses

same thing ahhhh...

bwkaz
09-15-2002, 08:50 AM
Is ncurses-devel installed (or whatever Slack calls it)?

The file that it's looking for is libncurses.so (assuming you told it -lncurses), so if it can't find that, it'll complain.

l01yuk
09-16-2002, 04:47 AM
Um, I said make sure you have the s in, ok you've done that.

Have you checked for the library files as I suggested? And as bwkaz just suggested?