0

sorry for my bad english. I make app in c with ncurses-5.9 lib. In docs for lib ( ncurses-5.9/doc/html/man/curs_util.3x.html ) I found what function key_name defined in curses.h, but if I include curses.h, I still get error key_name was not declared in this scope.

What i need to do for to use key_name function?

Chirag Desai
  • 1,249
  • 1
  • 10
  • 22
Kmd
  • 337
  • 2
  • 5
  • 18
  • Please post exact error compiler shows. also give the command you use to compile. – Chirag Desai May 20 '13 at 11:05
  • ex.c: In function ‘main’: ex.c:8:16: warning: initialization makes pointer from integer without a cast [enabled by default] /tmp/ccNpFkix.o: In function main': ex.c:(.text+0x21): undefined reference to key_name' collect2: ld returned 1 ex – Kmd May 20 '13 at 11:29

2 Answers2

1

Try to include <ncurses.h> as well.

And be sure that it is properly installed on your distro, and that you link it correctly at compilation.

If you still have trouble, check where the files are.

$sudo updatedb
$locate curses.h
$locate ncurses.h

Edit:

From the error you pasted, it shows that it's not a problem of header inclusion. LD (the linker) can't find the symbol associated to key_name. Which means that your are not compiling with the correct libray (maybe path issues) or that you need an extra one, or that key_name does'nt exist in the version you are trying to use.

And I think you are not passing the good parameter in the function, you are using "wint_t" instead of "wchar_t", It might be why it can't find the function.

And also try -lcurses in addition

Maresh
  • 4,644
  • 25
  • 30
  • I include curses.h and ncurses.h, i use -lncurses but still get same error – Kmd May 20 '13 at 10:54
  • Could you paste the compiler output please. – Maresh May 20 '13 at 10:56
  • Src example
    #include 
    #include 
    #include 
    #include 
    int main(int argc, char *argv[]) 
    {
      wint_t c = '\n';
      char *name = key_name(c);
      printf("Char name : %s\n",name); 
      return 0;
    }
    
    Compile `gcc ex.c -lncurses` Err: ex.c: In function ‘main’: ex.c:8:16: warning: initialization makes pointer from integer without a cast [enabled by default] /tmp/ccNpFkix.o: In function `main': ex.c:(.text+0x21): undefined reference to `key_name' collect2: ld returned 1 exit status
    – Kmd May 20 '13 at 11:14
  • It's not a problem of headers, it's a problem of linking. I will edit my post. – Maresh May 20 '13 at 11:30
1

For use key_name we must use libncursesw5-dev instead of libncurses5-dev.

Kmd
  • 337
  • 2
  • 5
  • 18