I am having trouble building Pinfo.

My configure line looks like this: ./configure --prefix=/usr/mylocal --with-curses=/usr/mylocal

The error message I get is
checking location of curses.h file... /usr/mylocal/include/ncurses/ncurses.h
checking if curses is usable... no
configure: error: Curses not found. You need curses to compile pinfo

However, it manages to locate ncurses.h as you can tell from this excerpt from config.log, but then claims the routines are missing. If I try building conftest.c myself with --save-temps and then look at conftest.i, each routine is defined as "extern WINDOW *", for example "extern WINDOW * stdscr;". There is also a "typedef struct _win_st WINDOW;" statement to define WINDOW.

configure:9858: checking location of curses.h file
configure:9901: result: /usr/mylocal/include/ncurses/ncurses.h
configure:10142: checking if curses is usable
configure:10171: gcc -o conftest -g -O2 -I/usr/mylocal/include -L/usr/mylocal/lib -lncurses conftest.c >&5
/tmp/ccAGkDPW.o: In function `main':
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:37: undefined reference to `initscr'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:38: undefined reference to `printw'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:39: undefined reference to `stdscr'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:39: undefined reference to `wrefresh'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:40: undefined reference to `stdscr'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:40: undefined reference to `wgetch'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:40: undefined reference to `stdscr'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:40: undefined reference to `wgetch'
/home/myuser/apps/wip/pinfo-0.6.9/conftest.c:41: undefined reference to `endwin'
collect2: ld returned 1 exit status
configure:10177: $? = 1
configure: failed program was:
|
| /* confdefs.h. */
|
| #define PACKAGE_NAME "pinfo"
| #define PACKAGE_TARNAME "pinfo"
| #define PACKAGE_VERSION "0.6.9"
| #define PACKAGE_STRING "pinfo 0.6.9"
| #define PACKAGE_BUGREPORT "pinfo-devel@lists.alioth.debian.org"
| #define PACKAGE "pinfo"
| #define VERSION "0.6.9"
| #define HAVE_STRDUP 1
| #define HAVE_STRSTR 1
| #define HAVE_STRSEP 1
| #define HAVE_GETOPT_LONG 1
| #define HAVE_SNPRINTF 1
| #define HAVE_SIGBLOCK 1
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define HAS_READLINE 1
| /* end confdefs.h. */
|
| #include
|
| int
| main ()
| {
|
| initscr();
| printw("Hello World !!!");
| refresh();
| getch();
| endwin();
| return 0;
|
|
| ;
| return 0;
| }
configure:10202: result: no
configure:10546: error: Curses not found. You need curses to compile pinfo

However, all the routines are there when I check /usr/mylocal/include/ncurses/ncurses.h

$ grep -w initscr /usr/mylocal/include/ncurses/ncurses.h
extern NCURSES_EXPORT(WINDOW *) initscr (void); /* implemented */
$ grep -w printw /usr/mylocal/include/ncurses/ncurses.h
extern NCURSES_EXPORT(int) printw (const char *,...) /* implemented */
$ grep -w refresh /usr/mylocal/include/ncurses/ncurses.h
#define _HASMOVED 0x20 /* has cursor moved since last refresh? */
extern NCURSES_EXPORT(int) refresh (void); /* generated */
#define refresh() wrefresh(stdscr)
#define KEY_REFRESH 0565 /* refresh key */
#undef refresh
$ grep -w getch /usr/mylocal/include/ncurses/ncurses.h
extern NCURSES_EXPORT(int) getch (void); /* generated */
#define getch() wgetch(stdscr)
$ grep endwin /usr/mylocal/include/ncurses/ncurses.h
extern NCURSES_EXPORT(int) endwin (void); /* implemented */
extern NCURSES_EXPORT(bool) isendwin (void); /* implemented */
$

I managed to get it to build using
gcc -o conftest.o conftest.c -I/usr/mylocal/include -g -L/usr/mylocal/lib -lncurses
instead of
gcc -o conftest -g -O2 -I/usr/mylocal/include -L/usr/mylocal/lib -lncurses conftest.c
so lets try
gcc -o conftest conftest.c -g -O2 -I/usr/mylocal/include -L/usr/mylocal/lib -lncurses

Hmm. Looks like it has something to do with the position of the source file in the command which is very strange as the manual says

You can mix options and other arguments. For the most part, the order you use doesn't matter. Order does matter when you use several options of the same kind; for example, if you specify -L more than once, the directories are searched in the order specified.

So for the time being, I have modified configure so that the definition for ac_link (in 9 places) is now ac_link='$CC -o conftest$ac_exeext conftest.$ac_ext $CFLAGS $CPPFLAGS $LDFLAGS $LIBS >&5'

An excellent guide to gcc and other utilities by BRUCE PERENS can be found at faqs.org


Details of hunt for initscr from ncurses.h

C:
  1. //usr/mylocal/include/ncurses/ncurses.h
  2. extern NCURSES_EXPORT(WINDOW *) initscr (void);                         /* implemented */
  3. NCURSES_EXPORT(int) vsscanf(const char *, const char *, va_list);
  4. #define vsscanf(a,b,c) _nc_vsscanf(a,b,c)
  5. typedef struct _win_st WINDOW;
  6.  
  7. struct _win_st
  8. {
  9.         NCURSES_SIZE_T _cury, _curx; /* current cursor position */
  10.  
  11.         /* window location and size */
  12.         NCURSES_SIZE_T _maxy, _maxx; /* maximums of x and y, NOT window size */
  13.         NCURSES_SIZE_T _begy, _begx; /* screen coords of upper-left-hand corner */
  14.  
  15.         short   _flags;         /* window state flags */
  16.  
  17.  
  18.         /* attribute tracking */
  19.         attr_t  _attrs;         /* current attribute for non-space character */
  20.         chtype  _bkgd;          /* current background char/attribute pair */
  21.  
  22.         /* option values set by user */
  23.         bool    _notimeout;     /* no time out on function-key entry? */
  24.         bool    _clear;         /* consider all data in the window invalid? */
  25.         bool    _leaveok;       /* OK to not reset cursor on exit? */
  26.         bool    _scroll;        /* OK to scroll this window? */
  27.         bool    _idlok;         /* OK to use insert/delete line? */
  28.         bool    _idcok;         /* OK to use insert/delete char? */
  29.         bool    _immed;         /* window in immed mode? (not yet used) */
  30.         bool    _sync;          /* window in sync mode? */
  31.         bool    _use_keypad;    /* process function keys into KEY_ symbols? */
  32.         int     _delay;         /* 0 = nodelay, <0 = blocking,>0 = delay */
  33.  
  34.         struct ldat *_line;     /* the actual line data */
  35.  
  36.         /* global screen state */
  37.         NCURSES_SIZE_T _regtop; /* top line of scrolling region */
  38.         NCURSES_SIZE_T _regbottom; /* bottom line of scrolling region */
  39.  
  40.         /* these are used only if this is a sub-window */
  41.         int     _parx;          /* x coordinate of this window in parent */
  42.         int     _pary;          /* y coordinate of this window in parent */
  43.         WINDOW  *_parent;       /* pointer to parent if a sub-window */
  44.  
  45.         /* these are used only if this is a pad */
  46.         struct pdat
  47.         {
  48.             NCURSES_SIZE_T _pad_y,      _pa
  49.             NCURSES_SIZE_T _pad_top,    _pad_left;
  50.             NCURSES_SIZE_T _pad_bottom, _pad_right;
  51.         } _pad;
  52.  
  53.         NCURSES_SIZE_T _yoffset; /* real begy is _begy + _yoffset */
  54.  
  55. #ifdef _XOPEN_SOURCE_EXTENDED
  56.         cchar_t  _bkgrnd;       /* current background char/attribute pair */
  57. #if 0
  58.         int     _color;         /* current color-pair for non-space character */
  59. #endif
  60. #endif
  61. }

Bookmark this article