简体   繁体   English

在为 PDCurses 编译此示例代码时,为什么仅未定义对 endwin() 的引用?

[英]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.在为 PDCurses 编译示例 hello-world.c 时,linker 似乎无法找到 endwin() function。 Commenting out the line containing endwin() , the code compiles fine and the program runs.注释掉包含endwin()的行,代码编译正常并且程序运行。

Here's the example code, taken from here (from source/pdce0.c):这是示例代码,取自此处(来自 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使用 mingw64 shell 编译时,抛出以下错误

$ 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.如上所述,在代码中注释掉endwin()会导致编译无错。

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 .我的设置是在 Win10 上安装 MSYS2,我根据MSYS 文档这个问题描述的步骤为 mingw64 安装了 mingw64 工具链和 PDCurses。

I tried linking the curses lib in different ways, -lncurses , -llibpdcurses , but this does not help.我尝试以不同的方式链接 curses 库, -lncurses-llibpdcurses ,但这没有帮助。

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' .我尝试了在上述 GitHub 存储库中找到的curses.h ,它看起来简单得多,但这只是将错误更改为undefined reference to 'endwin'

Edit 1 regarding comments编辑 1 关于评论

Concerning the internal definition of endwin() as a macro, I found this part in the include\pdcurses\curses.h关于 endwin() 作为宏的内部定义,我在 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.示例存储库中的 curses.h 中未包含类似的定义。

Still, endwin() doesn't seem to be defined in the lib.尽管如此, endwin() 似乎并未在库中定义。 I already tried reinstalling the pdcurses package via pacman , but everything seems to be fine on that end.我已经尝试通过pacman重新安装 pdcurses package ,但在那一端似乎一切都很好。

Could using another of the MSYS shells or another package be of help?使用另一个 MSYS shell 或另一个 package 会有帮助吗? 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编辑 2我只是看了一下其他一些例子,发现添加了一个无限循环,比如

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.我必须补充一点,我对 C、编译和其他一切都比较陌生,所以如果这个问题需要进一步阅读,我很乐意提出建议。

Using #include <pdcurses.h> lets it compile without error (this is kinda the direction, John Bollinger mentioned in his comment ).使用#include <pdcurses.h>可以让它编译无误(这是方向, John Bollinger 在他的评论中提到)。 I found this issue on the MSYS2/MINGW-Packages GitHub, leaving the impression, that my installation/build version of pdcurses might need some attention.我在 MSYS2/MINGW-Packages GitHub 上发现了这个问题,给人的印象是我的pdcurses安装/构建版本可能需要注意。 Like one of the commenters there, I thought, that linking against pdcurses didn't need changes of the included headers.就像那里的一位评论者一样,我认为针对pdcurses的链接不需要更改包含的标头。 I'll look into the setup more thoroughly.我会更彻底地研究设置。

But just to get started and try some things out, everything seems to work for now.但只是为了开始并尝试一些事情,现在一切似乎都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM