Why is curses on linux giving me following error?

前端 未结 2 1823
我寻月下人不归
我寻月下人不归 2020-12-16 01:50

Trying to get getch() working to capture key press.

    #include 
    ...
    ...
    WINDOW *w;
    char f;

   w = initscr();
   timeout(30         


        
相关标签:
2条回答
  • 2020-12-16 02:16

    The above answers are correct but the format is:

    gcc -Wall program.c -o name_of_binary -lncurses

    When I did:

    gcc -Wall -lncurses program.c...

    It did not work so apparently it should be tacked on the end.

    0 讨论(0)
  • 2020-12-16 02:18

    That's a linking error. Are you linking to the curses library correctly?

    There are two steps involved in using a library in C.

    1. You #include the relevant header files from your source files. This is so your code knows what signatures of the library functions are. So you're doing this correctly.
    2. When compiling your code, you need to tell the linker to link to the relevant libraries, so it can find the definition of those functions. This is what you're not doing. Assuming you're using gcc then adding -lncurses to the compile line should do it. Here's an explanation of linking.
    0 讨论(0)
提交回复
热议问题