Error while compiling ncurses app on Mac OS X

Viewed 1340

I'm trying to compile ncurses based app on Mac OS X 10.6.8 but I get this error.

Undefined symbols for architecture x86_64:
  "_initscr", referenced from:
      _main in ccf8K8YG.o
  "_printw", referenced from:
      _main in ccf8K8YG.o
  "_stdscr", referenced from:
      _main in ccf8K8YG.o
  "_wrefresh", referenced from:
      _main in ccf8K8YG.o
  "_wgetch", referenced from:
      _main in ccf8K8YG.o
  "_endwin", referenced from:
      _main in ccf8K8YG.o

What could be the problem ?

1 Answers

I'm pretty sure this is because you're not including the ncurses library when compiling.

Try adding:

-lncurses

when compiling.

For example (for C++):

g++ -o hello main.cpp -lncurses

Or using gcc (for C):

gcc -o hello main.cpp -lncurses

This short command will compile and execute:

gcc -o hello main.cpp -lncurses && ./hello

This was my issue, I hope this helps someone.

Related