已链接ncursesw仍提示mvaddwstr隐式声明的问题求助
环境
平台
Windows 11 + GCC 17(MINGW2)
编译命令
gcc -o main.exe main.c -lncursesw ; ./main.exe
MINGW2头文件目录
C:\msys64\mingw64\include C:\msys64\mingw64\include\ncurses C:\msys64\mingw64\include\ncursesw
代码
代码功能为在窗口绘制边框。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <ncurses/curses.h> #include <wchar.h> int main() { initscr(); int row = 0; int col = 0; getmaxyx(stdscr, row, col); wchar_t * square = L"\u2588"; for (int i = 0; i < row; i++) { if (i == 0 || i == row - 1) { for (int j = 0; j < col; j++) { mvaddwstr(i, j, square); } } else { mvaddwstr(i, 0, square); mvaddwstr(i, col - 1, square); } } refresh(); getch(); endwin(); return 0; }
问题
编译器提示mvaddwstr函数隐式声明,但已在编译命令中显式链接ncursesw库(而非常规的ncurses)。
main.c:76:17: warning: implicit declaration of function 'mvaddwstr'; did you mean 'mvaddstr'? [-Wimplicit-function-declaration] 76 | mvaddwstr(i, j, square); | ^~~~~~~~~ | mvaddstr
尽管有该警告,程序仍可正常运行,但希望解决此警告。
已尝试的解决方案
- 尝试在代码中引入
ncursesw下的curses.h,警告仍存在:
#include <ncursesw/curses.h>
- 尝试在编译命令中添加
ncursesw目录的头文件引用,警告仍未消除:
gcc -o main.exe main.c -IC:\msys64\mingw64\include\ncurseswncursesw -lncursesw; ./main.exe
内容的提问来源于stack exchange,提问作者Blundergat
相关产品推荐
相关产品推荐

