What packages to install for ncurses?

Okay, so I'm a total noob at everything to do with programming, seeing as I have only been using Linux for about 2 months, and don't know that much c++, but I have a very frustrating problem; I'm trying to use the ncurses library, but when I compile my code in the terminal, it gives me all of the following errors:

/tmp/ccyYLOVi.o: In function `main':
first.cpp:(.text+0xa): undefined reference to `initscr'
first.cpp:(.text+0x16): undefined reference to `printw'
first.cpp:(.text+0x1b): undefined reference to `refresh'
first.cpp:(.text+0x20): undefined reference to `endwin'
collect2: ld returned 1 exit status





Here is the actual code:

#include <ncurses.h>

int main()
{
initscr();
printw("Some useless text");
refresh();
endwin();
return 0;
}




I have installed the package "ncurses-dev" using "sudo apt-get ncurses-dev", and it installed okay and everything, as far as I know. I don't know if it makes a difference, but I use Ubuntu 12.01. Thanks in advance, and sorry if I use any wrong terminology or anything!

-Peter
"Undefined reference" means that the compiler is happy with the function, but the linker cannot find the actual compiled code that is the function. You need to tell it which library to look in.

I would expect your command line to look something like this:

g++ first.cpp -lncurses

-l indicates a library to look in, so -lncurses instructs to look in the ncurses library.
Yup, that worked perfectly, thank you! And I meant *Ubuntu 12.04*, not 12.01
Last edited on
Topic archived. No new replies allowed.