Search code examples
ccompilationstatic-librariesstatic-linkingncurses

How can I change the ESCDELAY value for C ncurses when I'm statically linking the libraries at compile time?


I have a program that I wrote using the C ncurses library. In this program, near the top I have this line:

ESCDELAY = 0;

This line is used to remove the delay that comes when pressing the escape key in ncurses.

I can compile this program normally like so:

gcc program.c -o program -lncurses

I have the correct libraries for static linking installed and set up, but when I try to compile my program statically:

gcc -static program.c -o program -lncurses

I get this error:

/usr/bin/ld: /usr/local/lib/libncurses.a(lib_getch.o):(.data+0x0): multiple definition of `ESCDELAY'; /tmp/ccMFQAm6.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status

When I remove the ESCDELAY = 0; line from my code and compile it statically like before, it compiles and works just fine.

So, how can I statically compile my code while changing the ESCDELAY value?


Solution

  • For man set_escdelay:

    The ESCDELAY and TABSIZE global variables are modified by some applications. To modify them in any configuration, use the set_escdelay or set_tabsize functions. Other global variables are not modifiable.

    You should replace

    ESCDELAY = 0;
    

    by

    set_escdelay(0);