You are not logged in.

#1 2020-04-29 12:13:38

Dazzac
Member
Registered: 2020-03-24
Posts: 2

[SOLVED] Haskell: Cabal and NCurses

Hi!

I am having troubles with building ncurses on Arch 5.5.13 and Cabal 3.2.0.0

I am getting the following error upon using

cabal install ncurses --lib
Configuring ncurses-0.2.16...
Preprocessing library for ncurses-0.2.16..
dist/build/UI/NCurses.chs.h:10:10: fatal error: ncursesw/ncurses.h: No such file or directory
   10 | #include <ncursesw/ncurses.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
c2hs: Error during preprocessing custom header file
cabal: Failed to build ncurses-0.2.16. See the build log above for details.

I've looked at the following links and came to the conclusion it's an issue with the way Arch stores the header files for ncurses:

https://bbs.archlinux.org/viewtopic.php?id=248318
https://stackoverflow.com/questions/473 … g-to-build
https://stackoverflow.com/questions/219 … y-in-cabal

I have tried the

--extra-include-dirs=/usr/include

flag to try and direct cabal to where ncurses is located, but this didn't work and i suspect its an issue with cabal, maybe it was for an older version of cabal?

Next i tried using

cc-options: -DHSNCURSES_NARROW_HEADER
pkgconfig-depends: ncurses, panel

Within the .cabal file but this provided the same error as above.

Any pointers would be appreciated!

Last edited by Dazzac (2020-04-29 22:53:30)

Offline

#2 2020-04-29 18:12:03

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,426

Re: [SOLVED] Haskell: Cabal and NCurses

You're wrong, and the haskell package is wrong.

https://john-millikin.com/code/haskell- … es.chs#190

#ifdef HSNCURSES_NARROW_HEADER
#include <ncurses.h>
#else
#include <ncursesw/ncurses.h>
#endif

But it is *never* correct to use ncursesw/ncurses.h, it is only ever correct to use ncurses.h -- if ncurses is configured with the non-default option --disable-overwrite then it will install headers to /usr/include/ncursesw and, critically, you're expected to use -I/usr/include/ncursesw. Even the pkg-config file generator in the ncurses sources will if --disable-overwrite is given, add pkg-config *.pc instructions as well as ncurses-config instructions to include this -I/usr/include/ncursesw

If this entire ill-advised ifdef is removed, and the software includes <ncurses.h> and links to pkg-config, this works correctly.

If you locally ensure HSNCURSES_NARROW_HEADER is defined then it "should" also work, though not correctly. I am confused why it doesn't work for you, but then, my knowledge of ghc is dreary and lacking, so I have no explanation.


EDIT: does the linked forum thread's recommendation for the haskell flag force-narrow-library, solve the problem?

Last edited by eschwartz (2020-04-29 18:18:41)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2020-04-29 22:52:44

Dazzac
Member
Registered: 2020-03-24
Posts: 2

Re: [SOLVED] Haskell: Cabal and NCurses

eschwartz wrote:

You're wrong, and the haskell package is wrong.

https://john-millikin.com/code/haskell- … es.chs#190

#ifdef HSNCURSES_NARROW_HEADER
#include <ncurses.h>
#else
#include <ncursesw/ncurses.h>
#endif

But it is *never* correct to use ncursesw/ncurses.h, it is only ever correct to use ncurses.h -- if ncurses is configured with the non-default option --disable-overwrite then it will install headers to /usr/include/ncursesw and, critically, you're expected to use -I/usr/include/ncursesw. Even the pkg-config file generator in the ncurses sources will if --disable-overwrite is given, add pkg-config *.pc instructions as well as ncurses-config instructions to include this -I/usr/include/ncursesw

If this entire ill-advised ifdef is removed, and the software includes <ncurses.h> and links to pkg-config, this works correctly.

If you locally ensure HSNCURSES_NARROW_HEADER is defined then it "should" also work, though not correctly. I am confused why it doesn't work for you, but then, my knowledge of ghc is dreary and lacking, so I have no explanation.


EDIT: does the linked forum thread's recommendation for the haskell flag force-narrow-library, solve the problem?

Hi this has been really helpful thank you!

Your link to the code made me realise the flag was for the module ncurses itself, not to be used within my modules .cabal file. I was able to easily make a local copy and compile it fine using the flags, so yeah the forum page's method does in fact work.

To give context this is for use in a university assignment, my next problem was that i wasn't able to apply this flag during cabal build on my local module, with ncurses being built from hackage(?).

I corrected this by adding

 constraint: ncurses +force-narrow-library 

to my .cabal/config file, and running cabal clean, configure...etc.

Honestly cabal confuses me greatly, though this might just be due to using an outdated initial setup provided as starter code.

Thanks

Offline

Board footer

Powered by FluxBB