0

Platform

Windows 11 + GCC Compiler 17 (MINGW2)

Compilation Command

gcc -o main.exe main.c -lncursesw ; ./main.exe 

MINGW2 Include Directory

C:\msys64\mingw64\include
C:\msys64\mingw64\include\ncurses
C:\msys64\mingw64\include\ncursesw

Code

It simply draws a border around the window.

#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;
}

Issue

The compiler seems to believe that mvaddwstr is implicitly declared. However, I have explicitly linked the ncursesw library in the compilation command (as opposed to the regular ncurses).

main.c:76:17: warning: implicit declaration of function 'mvaddwstr'; did you mean 'mvaddstr'? [-Wimplicit-function-declaration]
   76 |                 mvaddwstr(i, j, square);
      |                 ^~~~~~~~~
      |                 mvaddstr

Despite the warning, the program works fine. However, I would like to resolve the warning nonetheless.

Attempted Solutions

I have tried to include the curses.h file from ncursesw in the code. However, the warning persists.

#include <ncursesw/curses.h>

I have also tried adding an include to the ncursesw directory in the compilation command, but the warning persists.

gcc -o main.exe main.c -IC:\msys64\mingw64\include\ncurseswncursesw -lncursesw; ./main.exe
Blundergat
  • 37
  • 7
  • 1
    Implicit declaration is a problem while object code is being created, not a link-time problem. It's saying you've got the wrong header, or the right declarations were not being exposed by the header because you've not set something right. Or, maybe, you've got a typo in the name (though that seems [unlikely](https://linux.die.net/man/3/mvaddwstr)). – Jonathan Leffler Apr 13 '23 at 02:19
  • Does [How to install ncurses on Windows?](https://stackoverflow.com/questions/75556484/how-to-install-ncurses-on-windows) help? – Jonathan Leffler Apr 13 '23 at 02:25
  • 1
    This answers your question: [ncurses get\_wch() function undeclared](https://stackoverflow.com/questions/66103288/ncurses-get-wch-function-undeclared) (there are a couple of duplicates) – Thomas Dickey Apr 13 '23 at 07:40

1 Answers1

0

Solution

As outlined in this solution, I simply had to enable wide character support with NCURSES_WIDECHAR.

Fixed Compilation Command

gcc -o main.exe main.c -DNCURSES_WIDECHAR=1 -lncursesw ; ./main.exe 
Blundergat
  • 37
  • 7