C Unable to find the ncurses package.

I get the following error when trying to compile a Linux progam:

* Unable to find the ncurses package.
* Install ncurses (ncurses-devel or libncurses-dev
* depending on your distribution).
*
* You may also need to install pkg-config to find the
* ncurses installed in a non-default location.

Code:
# Check the default paths in case pkg-config is not installed.
# (Even if it is installed, some distributions such as openSUSE cannot
# find ncurses by pkg-config.)
if [ -f /usr/include/ncursesw/ncurses.h ]; then
        echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\"
        echo libs=\"-lncursesw -lmenuw -lpanelw\"
        exit 0
fi

if [ -f /usr/include/ncurses/ncurses.h ]; then
        echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\"
        echo libs=\"-lncurses -lmenu -lpanel\"
        exit 0
fi

if [ -f /usr/include/ncurses.h ]; then
        echo cflags=\"-D_GNU_SOURCE\"
        echo libs=\"-lncurses -lmenu -lpanel\"
        exit 0
fi

echo >&2 "*"
echo >&2 "* Unable to find the ncurses package."
echo >&2 "* Install ncurses (ncurses-devel or libncurses-dev"
echo >&2 "* depending on your distribution)."
echo >&2 "*"
echo >&2 "* You may also need to install pkg-config to find the"
echo >&2 "* ncurses installed in a non-default location."
echo >&2 "*"
exit 1

What do I need to change so that ncurses.h can be located?
 
You could try installing the devel/ncurses package. I'm lucky. I have two versions. Don't know why:
Code:
[strand.166] $ freebsd-version
13.2-RELEASE-p2
[strand.167] $ pkg info | grep ncurses
ncurses-6.4                    Library for terminal-independent, full-screen output
[strand.168] $ pkg search ncurses
braincurses-1.1.0_5            Clone of the Mastermind game
fpc-ncurses-3.2.2_4            Free Pascal interface to the ncurses library
ncurses-6.4                    Library for terminal-independent, full-screen output
[strand.169] $ find /usr -mount -name '*ncurses.h*' 2>/dev/null
/usr/local/include/ncurses/ncurses.h
/usr/include/ncurses.h
[strand.170] $ ls -la /usr/local/include/ncurses/ncurses.h /usr/include/ncurses.h
lrwxr-xr-x  1 root  wheel  8 Apr  9  2021 /usr/include/ncurses.h -> curses.h
lrwxr-xr-x  1 root  wheel  8 Apr 25 11:25 /usr/local/include/ncurses/ncurses.h -> curses.h
[strand.171] $ ls -la /usr/local/include/ncurses/curses.h /usr/include/curses.h
-r--r--r--  1 root  wheel  100266 Apr  9  2021 /usr/include/curses.h
-rw-r--r--  1 root  wheel  100242 Apr 25 11:25 /usr/local/include/ncurses/curses.h
[strand.172] $ diff /usr/local/include/ncurses/ncurses.h /usr/include/ncurses.h | head -8
2c2
<  * Copyright 2018-2020,2021 Thomas E. Dickey                                *
---
>  * Copyright 2018-2019,2020 Thomas E. Dickey                                *
36c36
< /* $Id: curses.h.in,v 1.277 2021/09/24 16:07:37 tom Exp $ */
---
> /* $Id: curses.h.in,v 1.266 2020/02/08 10:51:53 tom Exp $ */
 
It looks like I already have the latest version installed.

I suspect Linux is looking in the wrong place so probably need to change the search path.

I have an ncurses.h in /usr/include/ and /usr/local/include/, so not sure why they are not being found.
 
I've never heard of this pkg but have just installed, although don't know if it needs any configuration, since I get the same result after installing it.
 
FreeBSD comes with ncursesw in the base.

The header file is located at /usr/include/ncurses.h, while this script from Linux expects it either at /usr/include/ncursesw/ncurses.h or at /usr/include/ncurses/ncurses.h.

I suggest to add the directory ncursesw to /usr/include and then put symbolic links of the ncurses headers into it.

# mkdir -p /usr/include/ncursesw
# cd /usr/include/ncursesw
# ln -s ../ncurses*.h ./
# ls -l
Code:
total 0
lrwxr-xr-x  1 root  wheel  16 Aug 28 12:31 ncurses_dll.h -> ../ncurses_dll.h
lrwxr-xr-x  1 root  wheel  12 Aug 28 12:31 ncurses.h -> ../ncurses.h

Then try again.
 
FreeBSD comes with ncursesw in the base.

The header file is located at /usr/include/ncurses.h, while this script from Linux expects it either at /usr/include/ncursesw/ncurses.h or at /usr/include/ncurses/ncurses.h.

I suggest to add the directory ncursesw to /usr/include and then put symbolic links of the ncurses headers into it.

# mkdir -p /usr/include/ncursesw
# cd /usr/include/ncursesw
# ln -s ../ncurses*.h ./
# ls -l
Code:
total 0
lrwxr-xr-x  1 root  wheel  16 Aug 28 12:31 ncurses_dll.h -> ../ncurses_dll.h
lrwxr-xr-x  1 root  wheel  12 Aug 28 12:31 ncurses.h -> ../ncurses.h

Then try again.
Brilliant! That works great.

Just wondering how the original should be amended to locate FreeBSD's ncurses instead of changing FreeBSD to suit.
 
Brilliant! That works great.

Just wondering how the original should be amended to locate FreeBSD's ncurses instead of changing FreeBSD to suit.
You could try:
sed -e "s|/usr/include/ncursesw|/usr/include|" -i "" /path/to/that/linux_build_script.sh

If you are lucky, the -D_GNU_SOURCE compile time flag takes then care of all the rest, in case it does not, you're on your own.
 
Nothing. Are you compiling it correctly?
I don't think that link is uptodate since gcc no longer is included in base FreeBSD, AFAIK.

I'm not sure why one of the tests above:-
Code:
if [ -f /usr/include/ncurses.h ]; then
        echo cflags=\"-D_GNU_SOURCE\"
        echo libs=\"-lncurses -lmenu -lpanel\"
        exit 0
fi
fails, but with the changes suggested by cyclaero, I'm able to create the OpenWrt configuration menu similar to

1693262722014.png
 
Tada
I did the NCurses book around 2018.

cc -v -o box box.c -lncurses
Code:
#include <ncurses.h>

int main(void)
{
    initscr();

    box(stdscr,0,0);
    mvaddstr(4,8,"Ta-da!");
    refresh();
    getch();

    endwin();
    return 0;
}
 
Because it was old work I had to recompile it.

/Backups/ncurses/16 # ./box
ld-elf.so.1: Shared object "libncurses.so.8" not found, required by "box"
 
FreeBSD comes with ncursesw in the base.

The header file is located at /usr/include/ncurses.h, while this script from Linux expects it either at /usr/include/ncursesw/ncurses.h or at /usr/include/ncurses/ncurses.h.

The code above also has:-

C:
if [ -f /usr/include/ncurses.h ]; then
        echo cflags=\"-D_GNU_SOURCE\"
        echo libs=\"-lncurses -lmenu -lpanel\"
        exit 0
fi

I don't understand why this fails since ncurses.h exists in the required location:


Code:
root@X1:/ # ls -al /usr/include/ncurses.h                                                                                                                                     
ls -al /usr/include/ncurses.h                                                                                                                                                 
lrwxr-xr-x  1 root  wheel  8 Dec  7  2018 /usr/include/ncurses.h -> curses.h
 
Can anyone explain what is going on here:-?

Bash:
PKG="ncursesw menuw panelw"
PKG2="ncurses menu panel"

if [ -n "$(command -v pkg-config)" ]; then
        if pkg-config --exists $PKG; then
                echo cflags=\"$(pkg-config --cflags $PKG)\"
                echo libs=\"$(pkg-config --libs $PKG)\"
                exit 0
        fi

        if pkg-config --exists $PKG2; then
                echo cflags=\"$(pkg-config --cflags $PKG2)\"
                echo libs=\"$(pkg-config --libs $PKG2)\"
                exit 0
        fi
fi

Do I need to run pkg-config=ncurses to invoke FreeBSD's curses?
 
Here's my latest attempt to create an OpenWrt Build System using FreeBSD.

I'd appreciate any feedback.

See https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem

Bash:
#########
#########
#########
#########     Changes required
#########     
#########     include inline patches
#########
#########     check if packages have been installed   
#########
#########
#########


pkg bootstrap -y

#  Install required pkgs

cat <<EOF | xargs pkg install -y
git
rsync
bash
gmake
gtar
gcc
gawk
ncurses
findutils
diffutils
patch
wget
getopt
coreutils
pkgconf
EOF

# Install OpenWrt Build System

mkdir /OpenWrt-BuildSystem
cd /OpenWrt-BuildSystem
git clone https://github.com/openwrt/openwrt.git
cd openwrt

# patch prereq-build.mk

patch  <<EOF
--- include/prereq-build.mk    2023-08-26 09:03:31.437266000 +0100
+++ -
@@ -149,6 +149,7 @@
     Please install an extended getopt version that supports --long, \\
     gnugetopt -o t --long test -- --test | grep '^ *--test *--', \\
     getopt -o t --long test -- --test | grep '^ *--test *--', \\
+    /usr/local/bin/getopt -o t --long test -- --test | grep '^ *--test *--', \\
     /usr/local/opt/gnu-getopt/bin/getopt -o t --long test -- --test | grep '^ *--test *--', \\
     /opt/local/bin/getopt -o t --long test -- --test | grep '^ *--test *--'))
EOF


#exit
pkg-config=ncurses

    # Let's go!!!

./scripts/feeds update -a
./scripts/feeds install -a


# mkdir -p /usr/include/ncursesw
# cd /usr/include/ncursesw
# ln -s ../ncurses*.h ./


make  menuconfig
 
Back
Top