Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT creator and MinGW project in C doesn't recognize ncurses.h



  • Hi, I'd like to know if anyone knows what I should include in my .pro file to be able to use:

    #include <ncurses.h>
    

    I tried with this but it doen't work. Thank you so much.

    #include <ncurses.h> /* ncurses.h includes stdio.h */
    #include <string.h>
    int main()
    {
        char mesg[]="Just a string"; /* message to be appeared on the screen */
        int row,col; /* to store the number of rows and *
     * the number of colums of the screen */
        initscr(); /* start the curses mode */
        getmaxyx(stdscr,row,col); /* get the number of rows and columns */
        mvprintw(row/2,(col−strlen(mesg))/2,"%s",mesg);
        /* print the message at the center of the screen */
        mvprintw(row−2,0,"This screen has %d rows and %d columns\n",row,col);
        printw("Try resizing your window(if possible) and then run this program again");
        refresh();
        getch();
        endwin();
        return 0;
    }
    
    


  • @ale-fdezsuarez said in QT creator and MinGW project in C doesn't recognize ncurses.h:

    I tried with this but it doen't work.

    What does this mean? Didn't compile? Didn't link? Didn't run? Didn't do what you want? Did you really get no error message anywhere, just "didn't work"? We are not guess-experts...!

    For my guess: either it didn't find /usr/include/ncurses.h to include (doubtful), or you need to tell it which libncurses... to link against.

    EDIT
    OK, sorry, I only just just noticed your this word was a link :) So that said:

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

    which looks about right. What paths did you put there, and did you check there is a ncurses.h file in the INCLUDEPATH directory and a libncurses.a file in the LIBS directory? And still we need to know: did it fail at compile time (INCLUDEPATH) or at link time (LIBS), and with what message?



  • This post is deleted!


  • @JonB First of all thank you for you answer.

    No, I couldn't check if they are on the INCLUDEPATH routes because I don't know where those routes are in QT (I just started using it).

    The error is given to me in the .c file that underlines the

    #include <ncurses.h>
    ``` and puts me:
    
    

    principal.c:2:10: error: 'ncurses.h' file not found



  • @ale-fdezsuarez said in QT creator and MinGW project in C doesn't recognize ncurses.h:

    principal.c:2:10: error: 'ncurses.h' file not found

    OK, that's a bit more helpful! :)

    So, I don't know where it is on the PC, presumably somewhere in the MinGW installed area(?), you need to find a file named ncurses.h. And then you need to go like that answer said in your .pro file:

    INCLUDEPATH += /path/to/ncurses/headers/
    

    And then similarly for the LIBS line for the path to a file named libncurses.a.



  • @JonB So in my case:

    ncurses.png libncurses.png

    And if I go to the .pro file I write:

    INCLUDEPATH += C:\Qt\Tools\mingw810_32\opt\include\ncursesw
    LIBS += -LC:\Qt\Tools\mingw810_32\opt\lib
    

    And I get two errors when I compile it :(

    :-1: error: error: LC:\Qt\Tools\mingw810_32\opt\include\ncursesw: Invalid argument
    :-1: error: [Makefile.Debug:68: debug/Test_curses_002.exe] Error 1
    


  • @ale-fdezsuarez said in QT creator and MinGW project in C doesn't recognize ncurses.h:

    LIBS += -LC:\Qt\Tools\mingw810_32\opt\lib

    Why do you write this when the solution you read, and what I pasted above, reads:

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

    ? I just don't get it. There is a reason people paste answers, you have to read and follow, not just ignore bits of it and then wonder why it doesn't work....

    P.S.

    :-1: error: error: LC:\Qt\Tools\mingw810_32\opt\include\ncursesw: Invalid argument

    Could you explain how you get this error message from what you show you added into the .pro. Where does that leading L come from? Or, is that error message actually from writing something different from what you show?



  • @JonB I notice the OP is using backslashes in his path. As I recall, this causes problems in a project file. The other thing is that the -L/-l convention comes from Linux; does this actually work with Windows libraries? I seem to recall trying to use that once, and ran into issues I can't remember anymore.


  • Lifetime Qt Champion

    @mzimmers

    I notice the OP is using backslashes in his path. As I recall, this causes problems in a project file.

    Correct. Using forward slashes is the way to go.

    The other thing is that the -L/-l convention comes from Linux; does this actually work with Windows libraries? I seem to recall trying to use that once, and ran into issues I can't remember anymore.

    Using -L and -l is cross-platform and should be used on Windows with MSVC and MinGW also. Qt Creator recognizes this syntax and extends the library search paths when running the app.

    If you have problems here, then you probably messed up the syntax - which I had in former times also ;)

    Regards


Log in to reply