1

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.

JanS
  • 11
  • 4
  • 2
    In the first place, you cannot pick a random curses header. You must use the one that goes with the curses library you are using. – John Bollinger Jan 17 '23 at 15:39
  • It doesn't say endwin, it says endwin_x64_4302. Weird. is endwin defined as a macro accidentally? – user253751 Jan 17 '23 at 15:44
  • 1
    The usual answer to an "undefined reference" issue is that you failed to link the correct library or that the order of the objects on the link command line is wrong. Neither of those appears to be the case here, however. – John Bollinger Jan 17 '23 at 15:45
  • 1
    @user253751, I would be inclined to guess that `endwin` is defined as a macro *intentionally* (by the pdcurses project or by those who packaged it for MSYS2). That kind of thing is sometimes done, perhaps more often than you think. But it may be that there is a bug somewhere that is producing a mismatch between the macro and the actual name of the function as it exists in the library. – John Bollinger Jan 17 '23 at 15:47
  • A lot of the "functions" in the `` (or ``) library are actually macros defined by the header. – Jonathan Leffler Jan 17 '23 at 20:38

1 Answers1

0

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.

JanS
  • 11
  • 4