clinkermingw-w64msys2pdcurses

Why is only the reference to endwin() not defined, when compiling this example code for PDCurses?


When compiling the example hello-world.c for PDCurses, the linker can't seem to find the endwin() function only. Commenting out the line containing endwin(), the code compiles fine and the program runs.

Here's the example code, taken from here (from source/pdce0.c):

#include <curses.h>


/* hello world, initialize curses */
int main()
{
    initscr();
    printw("Hello World !!!");
    refresh();
    getch();
    endwin();

    return 0;
}

When compiling using the mingw64 shell, the following error get's thrown

$ gcc -W -Wall -Ic:/Tools/msys64/mingw64/include/pdcurses -o test hello-world.c -lpdcurses
C:/Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Tools\msys6
4\tmp\ccsKgZ37.o:hello-world.c:(.text+0x39): undefined reference to `endwin_x64_4302'
collect2.exe: error: ld returned 1 exit status

As stated above, commenting out endwin() in the code leads to compilation without error.

My setup is a MSYS2 installation on Win10 and I installed the mingw64 toolchain and PDCurses for mingw64 according to the steps described by the MSYS doc and this question.

I tried linking the curses lib in different ways, -lncurses, -llibpdcurses, but this does not help.

I tried the curses.h found in the above stated GitHub repo, it looks much simpler, but all this does is change the error to undefined reference to 'endwin'.

Edit 1 regarding comments

Concerning the internal definition of endwin() as a macro, I found this part in the include\pdcurses\curses.h

#ifdef PDC_WIDE
   #ifdef PDC_FORCE_UTF8
      #ifdef CHTYPE_32
         #define endwin endwin_u32_4302
      #else
         #define endwin endwin_u64_4302
      #endif
   #else
      #ifdef CHTYPE_32
         #define endwin endwin_w32_4302
      #else
         #define endwin endwin_w64_4302
      #endif
   #endif
#else       /* 8-bit chtypes */
   #ifdef CHTYPE_32
      #define endwin endwin_x32_4302
   #else
      #define endwin endwin_x64_4302
   #endif
#endif

A comparable definition is not included in the curses.h from the examples repo.

Still, endwin() doesn't seem to be defined in the lib. I already tried reinstalling the pdcurses package via pacman, but everything seems to be fine on that end.

Could using another of the MSYS shells or another package be of help? I'll see what I can find out.

Edit 2 I just took a look at some of the other examples and found out, that adding an infinite loop like

int main()
{
    initscr();
    printw("Hello World !!!");
    while(1){
       refresh(); 
    }
    getch();
    endwin();

    return 0;
}

also compiles without the error, but of course produces an unresponsive program.

I have to add that I'm rather new to C, compiling and everything, so if this problems requires some further reading, I'd be glad about suggestions.


Solution

  • Using #include <pdcurses.h> lets it compile without error (this is kinda the direction, John Bollinger mentioned in his comment). I found this issue on the MSYS2/MINGW-Packages GitHub, leaving the impression, that my installation/build version of pdcurses might need some attention. Like one of the commenters there, I thought, that linking against pdcurses didn't need changes of the included headers. I'll look into the setup more thoroughly.

    But just to get started and try some things out, everything seems to work for now.