Reputation: 51
I need to use ncurses with unicode support, so I included the following line to my .c file.
#include <curses.h>
In my makefile I'm using -lncursesw as a flag. When calling functions like get_wch(), it tells me "implicit declaration of function". I'm on Arch Linux so I installed ncurses with pacman -S ncurses. In /usr/include I can find cursesw.h, but it doesn't have functions like get_wch() declared. Under /lib I can find libcursesw.so, so what's the matter?
Upvotes: 3
Views: 1554
Reputation: 54485
Use <curses.h>
, read the header file to see which definition you prefer using:
/*
* With XPG4, you must define _XOPEN_SOURCE_EXTENDED, it is redundant (or
* conflicting) when _XOPEN_SOURCE is 500 or greater. If NCURSES_WIDECHAR is
* not already defined, e.g., if the platform relies upon nonstandard feature
* test macros, define it at this point if the standard feature test macros
* indicate that it should be defined.
*/
#ifndef NCURSES_WIDECHAR
#if defined(_XOPEN_SOURCE_EXTENDED) || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500))
#define NCURSES_WIDECHAR 1
#else
#define NCURSES_WIDECHAR 0
#endif
#endif /* NCURSES_WIDECHAR */
(just NCURSES_WIDECHAR
should be enough). This is summarized in the manual page.
If you read cursesw.h
, you might notice that it is for the C++ binding.
As suggested in another answer, you can get some help from the pkg-config program. However, that gives different results for Arch Linux:
$ pkg-config ncurses --cflags --libs
-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -lncursesw
$ pkg-config ncursesw --cflags --libs
-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -lncursesw
That is, the Arch Linux packager has equated the two configurations of ncurses; both selections in pkg-config
use the ncursesw
library. The Arch Linux package does have a libncurses.so
, but that is only a text-file telling the linker to use libncursesw.so
. Because of the way it is packaged, on Arch Linux it makes no difference which library you use.
(offhand, combining _GNU_SOURCE
and _DEFAULT_SOURCE
is incorrect, probably not from any distribution's packaging system, because the former was deprecated in ncurses five years ago).
Upvotes: 1
Reputation: 13676
-lncursesw
is a linker flag, and by itself is not enough to enable wide char support. You should also add the compiler flag -I/usr/include/ncursesw
. Without this your #include <curses.h>
will end up including /usr/include/curses.h
instead of /usr/include/ncursesw/curses.h
If you want a more standard way to find out required linker and compiler flags, you can use pkg-config
. See the difference between those:
$ pkg-config ncurses --cflags --libs
-D_GNU_SOURCE -D_DEFAULT_SOURCE -lncurses -ltinfo
$ pkg-config ncursesw --cflags --libs
-D_GNU_SOURCE -D_DEFAULT_SOURCE -I/usr/include/ncursesw -lncursesw -ltinfo
Upvotes: 2