You are not logged in.
Hello,
I want to write an application using the c++ bindings of the ncurses library.
I managed to compile something like :
#include <curses.h>
#include <cursesw.h>
int main()
{
NCursesWindow *test;
return (0);
}
But when I start to use C++ symbols such as a NCursesWindow constructor (which is present and public in the cursesw.h header file) :
#include <curses.h>
#include <cursesw.h>
int main()
{
NCursesWindow *test = new NCursesWindow(10, 10, 0, 0);
(void)test;
return (0);
}
I get the error :
$ make
g++ -W -Wall -Wextra -I Includes/ -std=c++11 -c -o Sources/main.o Sources/main.cpp
g++ -o cppcurses Sources/main.o -lncurses
Sources/main.o: In function `main':
main.cpp:(.text+0x31): undefined reference to `NCursesWindow::NCursesWindow(int, int, int, int)'
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'cppcurses' failed
make: *** [cppcurses] Error 1
So I was wondering : are the c++ bindings activated in the ncurses library provided by the core repository ? And if not, shouldn't they be ?
(It works fine if I link the libncurses++.a created by downloading and building the library from the sources, but I find it quite inconvenient)
Thanks !
Last edited by Unda (2014-10-12 01:08:08)
Offline
edit: oops, I misread, sorry. I get the same error here - but I'm not good with troubleshooting c++.
Last edited by Trilby (2014-10-12 01:00:10)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I'm not quite sure what you are trying to achieve but you can try using this to compile:
-lncursesw
Personal spot :: https://www.smirky.net/ :: Try not to get lost!
Offline
@smirky, yes I tried that too when I saw it inspecting the /usr/lib directory, but the same problem occurs.
By the way, there doesn't seem be C++ symbols in the libncurses.so nor libncursesw.so. I checked with
nm -D libfile
Does anyone know where I can find information or ask how the ncurses package was built ?
Last edited by Unda (2014-10-12 11:58:34)
Offline
Hi Unda, you can use abs to download the source pkgbuild of any official package.
In your case, beacuse you are intresed only in ncurses package, you can use the following commands to retrieve the pkgbuild:
$ mkdir ~/abs
$ ABSROOT=~/abs abs core/ncurses
Now you can inspect the PKGBUILD file located in ~/abs/core/ncurses to see how the package was built.
Regarding the compilation error, you're right: in order to compile your code, you needs the library libncurses++.a or libncurses++.so.
Archlinux however has a strict "no static libraries" policy (take a look to this thread if you want to know why https://bbs.archlinux.org/viewtopic.php?id=188217) therefore you will find a static library very rarely in an official package, moreover makepkg will remove by default all the static libraries in your packages unless you explicitly set the 'staticlibs' option in the pkgbuild and this is not the case.
I downloaded the PKGBUILD and tried to build the package myself:
First of all, the INSTALL file located in the folder of ncurses source code says
6. The c++ directory has C++ classes that are built on top of ncurses and
panels. You must have c++ (and its libraries) installed before you can
compile and run the demo.
Use --without-cxx-binding to tell configure to not build the C++ bindings
and demo.
So the c++ binding should be built by default however, just to be sure, I have added also the options --with-cxx-binding and --with-cxx-shared and now the build function is
build() {
cd ${srcdir}/
mkdir ncurses{,w}-build
cd ${srcdir}/ncursesw-build
../${pkgname}-${pkgver}/configure --prefix=/usr --mandir=/usr/share/man \
--with-shared --with-normal --without-debug --without-ada \
--enable-widec --enable-pc-files --with-cxx-binding --with-cxx-shared \
# add --enable-ext-colors and --enable-ext-mouse with next soname bump
make
# libraries for external binary support
cd ${srcdir}/ncurses-build
[ $CARCH = "x86_64" ] && CONFIGFLAG="--with-chtype=long"
../${pkgname}-${pkgver}/configure --prefix=/usr \
--with-shared --with-normal --without-debug --without-ada --with-cxx-binding --with-cxx-shared $CONFIGFLAG
make
}
The problem now is that even if the option --with-shared is passed to the configure script, libncurses++ will be compiled always a static library and then removed during the packaging process. I'm not sure if this should be treated as a bug but any software relying on pkg-config to retrieve the correct compiler options will get an unusable configuration because no libncurses++ exists
$ pkg-config --libs ncurses++
-lncurses++w -lpanelw -lmenuw -lformw -lncursesw
Offline
It's also several years out of date. Here's the (upstream) current source: ftp://invisible-island.net/ncurses/curr … ses.tar.gz
Last edited by stevenhoneyman (2014-10-12 14:34:00)
My: [ GitHub | AUR Packages ]
Offline
It's also several years out of date.
??? The upstream source you linked to is version 5.9. The version in the repos is 5.9. In what way is that several years out of date?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
stevenhoneyman wrote:It's also several years out of date.
??? The upstream source you linked to is version 5.9. The version in the repos is 5.9. In what way is that several years out of date?
The Arch source is the GNU "stable" version (dated April 2011) [1]
The upstream source hasn't changed version numbers, but has had hundreds of updates[2] since
I've contacted the developer to confirm compatibility (and raised a feature req on the Arch bugtracker[3] a while back)
...I mean, even debian* is using a more recent version! [4]
[1] http://ftp.gnu.org/pub/gnu/ncurses/
[2] http://invisible-island.net/ncurses/NEWS.html
[3] https://bugs.archlinux.org/task/41663
[4] https://packages.debian.org/jessie/libncurses5-dev
* A distro known for stability and not just "keeping version numbers up with everyone else"
My: [ GitHub | AUR Packages ]
Offline
Ah, that could be - though I can't imagine why upstream would have so many updates and not increment the version (even minor version) at all over several years. Arch does not - in general - put the most cutting edge development branches in the main repos (these can often be found in the AUR); rather arch devs tend to package the most recent versioned release from upstream sources. So if the upstream devs aren't releasing new versions, arch devs have little to do.
There is an ncurses-git-cxx package in the AUR which claims to have the c++ bindings. That may be the way to go.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Installing the ncurses-git-cxx package installs a libncurses++w.so and so linking with -lncurses++w works fine.
I also compiled the last ncurses sources (as pointed out by stevenhoneyman), but couldn't get a C++ bindings shared library though, so even if ncurses developpers release a new stable version, it would not solve the "no C++ shared library" problem pointed out by mauritiusdadd.
Last edited by Unda (2014-10-12 17:24:22)
Offline
Ah, that could be - though I can't imagine why upstream would have so many updates and not increment the version (even minor version) at all over several years
VCS instead of regular released versions seems to be how things are shifting towards. I'm sure there was some discussion not too long ago in either the "grrr" or "ooh nice" threads.
How about Pacman for example, but then there's many more. Blueman - there's another good example (that I just remembered about while typing this). After the bluez4->5 change, it went to git-only (although after nearly a year, they tagged alpha1.99)
Installing the ncurses-git-cxx package installs a libncurses++w.so and so linking with -lncurses++w works fine.
I also compiled the last ncurses sources (as pointed out by stevenhoneyman), but couldn't get a C++ bindings shared library though, so even if ncurses developpers release a new stable version, it would not solve the "no C++ shared library" problem pointed out by mauritiusdadd.
Did you remember to add "--with-cxx-binding --with-cxx-shared" when you compiled the snapshot? It's missing from the Arch script.
The result should be identical - the AUR package you mention is using an unofficial git repo that gets auto-populated with the weekly snapshot when it appears.
Last edited by stevenhoneyman (2014-10-12 18:18:29)
My: [ GitHub | AUR Packages ]
Offline
Did you remember to add "--with-cxx-binding --with-cxx-shared" when you compiled the snapshot? It's missing from the Arch script.
The result should be identical - the AUR package you mention is using an unofficial git repo that gets auto-populated with the weekly snapshot when it appears.
I just tried again to be sure, and the only c++ libraries generated are "libncurses++.a" and "libncurses++_g.a", so no shared library.
Offline
stevenhoneyman wrote:Did you remember to add "--with-cxx-binding --with-cxx-shared" when you compiled the snapshot? It's missing from the Arch script.
The result should be identical - the AUR package you mention is using an unofficial git repo that gets auto-populated with the weekly snapshot when it appears.I just tried again to be sure, and the only c++ libraries generated are "libncurses++.a" and "libncurses++_g.a", so no shared library.
Strange! Mine works...
$ ./configure --prefix=/usr --with-shared --with-cxx-binding --with-cxx-shared --enable-widec --disable-db-install --without-{manpages,debug,tests,progs}
$ make && make DESTDIR=$PWD/OUT install
OUT
└── usr
├── bin
│ └── ncursesw5-config
├── include
│ ├── cursesapp.h
│ ├── cursesf.h
│ ├── curses.h
│ ├── cursesm.h
│ ├── cursesp.h
│ ├── cursesw.h
│ ├── cursslk.h
│ ├── eti.h
│ ├── etip.h
│ ├── form.h
│ ├── menu.h
│ ├── ncurses_dll.h
│ ├── ncurses.h -> curses.h
│ ├── panel.h
│ ├── termcap.h
│ ├── term.h
│ └── unctrl.h
└── lib
├── libformw.a
├── libformw.so -> libformw.so.5
├── libformw.so.5 -> libformw.so.5.9
├── libformw.so.5.9
├── libmenuw.a
├── libmenuw.so -> libmenuw.so.5
├── libmenuw.so.5 -> libmenuw.so.5.9
├── libmenuw.so.5.9
├── libncurses++w.a
├── libncursesw.a
├── libncurses++w.so -> libncurses++w.so.5
├── libncursesw.so -> libncursesw.so.5
├── libncurses++w.so.5 -> libncurses++w.so.5.9
├── libncursesw.so.5 -> libncursesw.so.5.9
├── libncurses++w.so.5.9
├── libncursesw.so.5.9
├── libpanelw.a
├── libpanelw.so -> libpanelw.so.5
├── libpanelw.so.5 -> libpanelw.so.5.9
└── libpanelw.so.5.9
4 directories, 38 files
My: [ GitHub | AUR Packages ]
Offline
Ok, "--with-cxx-shared" doesn't imply the "--with-shared" option, so mine works too now, sorry for that.
So I guess now we just have to wait that Arch uses the snapshots instead of the stable releases ... Or use the AUR package until then.
Last edited by Unda (2014-10-12 18:48:38)
Offline
Ah, that could be - though I can't imagine why upstream would have so many updates and not increment the version (even minor version) at all over several years.
You might want to consider the version as "Major.Minor-Patchlevel", with patchlevel = patch date. It might be that the author interprets the version number in this way. The patches are mostly only bugfixes and therefore only warrant an increment in the patchlevel and not the minor version. Sometimes it is a bit inconsistent. I might have incremented the minor version a few times, especially for the 20141011 patch.
There is an ncurses-git-cxx package in the AUR which claims to have the c++ bindings. That may be the way to go.
The official package is flawed. It provides pkg-config definitions for ncurses++, but the library itself is missing. You should report a bug to add "--with-cxx-binding --with-cxx-shared" to the PKGBUILD.
Edit: Couldn't get it to work. Is that really all that is required or do you need one of the new patches?
Last edited by progandy (2014-10-12 20:58:57)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
Well, it seems that the configuration script provided by the ncurses source code is really messed up, the only way I was able to build a ncurses++.so is by passing the option --with-libtool and modifying the package function too...
Since it is not too big, I post the entire PKGBUILD here, it works for me and if someone else can confirm that it works, I'll file a bug report
# $Id: PKGBUILD 197156 2013-10-23 13:04:21Z allan $
# Maintainer: Allan McRae <allan@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>
pkgname=ncurses
pkgver=5.9
pkgrel=7
pkgdesc="System V Release 4.0 curses emulation library"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/ncurses/"
license=('MIT')
depends=('glibc')
source=(ftp://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz{,.sig})
md5sums=('8cb9c412e5f2d96bc6f459aa8c6282a1'
'014ffdbbfec6d41a9a89d6cbe6434638')
prepare() {
#cleaning the old building directories
cd ${srcdir}/
rm -Rf ./ncurses{,w}-build
}
build() {
cd ${srcdir}/
mkdir ncurses{,w}-build
cd ${srcdir}/ncursesw-build
../${pkgname}-${pkgver}/configure --prefix=/usr --mandir=/usr/share/man \
--with-shared --with-normal --without-debug --without-ada \
--enable-widec --enable-pc-files --with-cxx-binding --with-cxx-shared \
--with-libtool \
# add --enable-ext-colors and --enable-ext-mouse with next soname bump
make
# libraries for external binary support
cd ${srcdir}/ncurses-build
[ $CARCH = "x86_64" ] && CONFIGFLAG="--with-chtype=long"
../${pkgname}-${pkgver}/configure --prefix=/usr \
--with-shared --with-normal --without-debug --without-ada --with-cxx-binding \
--with-cxx-shared --with-libtool $CONFIGFLAG
make
}
package() {
cp -n ${srcdir}/ncurses-build/lib/.libs/*.so* ${srcdir}/ncurses-build/lib/
cp -n ${srcdir}/ncursesw-build/lib/.libs/*.so* ${srcdir}/ncursesw-build/lib/
for lib in ncurses form panel menu; do
cp -n ${srcdir}/ncurses-build/lib/lib${lib}.so ${srcdir}/ncurses-build/lib/lib${lib}.so.${pkgver}
cp -n ${srcdir}/ncursesw-build/lib/lib${lib}w.so ${srcdir}/ncursesw-build/lib/lib${lib}w.so.${pkgver}
done
cd ${srcdir}/ncursesw-build
../${pkgname}-${pkgver}/misc/shlib make DESTDIR=${pkgdir} install
# fool packages looking to link to non-wide-character ncurses libraries
for lib in ncurses form panel menu; do
echo "INPUT(-l${lib}w)" >${pkgdir}/usr/lib/lib${lib}.so
done
for lib in ncurses ncurses++ form panel menu; do
ln -s ${lib}w.pc ${pkgdir}/usr/lib/pkgconfig/${lib}.pc
done
# some packages look for -lcurses during build
echo "INPUT(-lncursesw)" >${pkgdir}/usr/lib/libcursesw.so
ln -s libncurses.so ${pkgdir}/usr/lib/libcurses.so
# non-widec compatibility libraries
cd ${srcdir}/ncurses-build
for lib in ncurses form panel menu; do
install -Dm755 lib/lib${lib}.so.${pkgver} ${pkgdir}/usr/lib/lib${lib}.so.${pkgver}
ln -s lib${lib}.so.${pkgver} ${pkgdir}/usr/lib/lib${lib}.so.5
done
# install license, rip it from the readme
cd ${srcdir}/${pkgname}-${pkgver}
install -dm755 ${pkgdir}/usr/share/licenses/$pkgname
grep -B 100 '$Id' README > ${pkgdir}/usr/share/licenses/${pkgname}/license.txt
}
Last edited by mauritiusdadd (2014-10-13 12:05:41)
Offline
File a bug report asking for those additions. They do not look too intrusive.
Offline
Thank you Allan, bug report sent (FS#42356).
And forgive me if I have been intrusive, it was not my intention.
Offline