I'm having some problems statically linking ncurses to one of my programs
Here's a really simple sample program:
gcc -static -lncurses hello_curses.c -o curses
/tmp/ccwHJ6o1.o: In function `main':
curses_hello.c:(.text+0x5): undefined reference to `initscr'
curses_hello.c:(.text+0x14): undefined reference to `printw'
curses_hello.c:(.text+0x1b): undefined reference to `stdscr'
curses_hello.c:(.text+0x20): undefined reference to `wrefresh'
curses_hello.c:(.text+0x27): undefined reference to `stdscr'
curses_hello.c:(.text+0x2c): undefined reference to `wgetch'
curses_hello.c:(.text+0x31): undefined reference to `endwin'
collect2: ld returned 1 exit status
You need to pass
-l options at the end of the command line:
gcc -static hello_curses.c -o curses -lncurses
When the compiler encounters
-lfoo, it links in all the symbols from
foo that have been requested by a previous file. If you put
-lfoo at the beginning, no symbol has been requested yet, so no symbol gets linked.