Qt World Summit: Register Today!

How to add ncurses library to project?

  • I am trying to start with ncurses library but QtCreator does not compile it. Here is the simple code:

    #include <iostream>
    #include <ncurses.h>
    using namespace std;
    int main(int argc, char *argv[])
        initscr();			/* Start curses mode 		  */
        printw("Hello World !!!");	/* Print Hello World		  */
        refresh();			/* Print it on to the real screen */
        getch();			/* Wait for user input */
        endwin();			/* End curses mode		  */
        return 0;

    I added to .pro file these lines but i could not find where i am doing wrong:

    QMAKE_CXXFLAGS += -lncurses
    QMAKE_CXXFLAGS_DEBUG += -lncurses

    When I compile it with g++ manually with -lncurses option it works though. QtCreator gives me undefined reference for those functions.

  • Hi! Your *.pro file should contain:

    INCLUDEPATH += /path/to/ncurses/headers/
    LIBS += -L/path/to/ncurses/library/ -lncurses

  • @Wieland I have just added this and it works:

    LIBS += -L/usr/include -lncurses

    But I dealed with finding include path still, I don't know why only -lncurses is not enough.

  • Lifetime Qt Champion

    Hi you also need to tell about
    .h files with
    INCLUDEPATH += /path/to/ncurses/headers/
    as @wieland says

  • Lifetime Qt Champion

    @maydin As libs are not located in include directories it should be:

    LIBS += -L/usr/lib -lncurses

Log in to reply