Search code examples
cgccncursescurses

Implicit declaration of "mvaddwstr" function despite ncursesw (wide variation of ncurses) being explicitly linked


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

Solution

  • 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