I'm trying to use ncurses in a library using Swift Package Manager and I'd like to use a specific version of ncurses, not the one included in OS X.
To do so I installed a more recent version (6.1) using Homebrew.
This is how my Package.swift
looks like:
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "NcursesExample",
products: [
.executable(name: "NcursesExample", targets: ["NcursesExample"]),
],
dependencies: [
],
targets: [
.systemLibrary(name: "Cncurses"),
.target(name: "NcursesExample", dependencies: ["Cncurses"]),
]
)
Under the Sources directory I have a subdirectory for Cncurses containing a module.modulemap
and shim.h
files:
module.modulemap
module Cncurses {
header "shim.h"
link "ncurses"
export *
}
shim.h
#include "/usr/local/Cellar/ncurses/6.1/include/ncurses.h"
However, when compiling I get several errors complaining about conflicting types, apparently because ncurses is also provided by the macOS SDK:
shim.h:1:10: note: in file included from shim.h:1:
#include "/usr/local/Cellar/ncurses/6.1/include/ncurses.h"
^
/usr/local/Cellar/ncurses/6.1/include/ncurses.h:60:10: error: 'ncursesw/ncurses_dll.h' file not found with <angled> include; use "quotes" instead
#include <ncursesw/ncurses_dll.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
^
shim.h:1:10: note: in file included from shim.h:1:
#include "/usr/local/Cellar/ncurses/6.1/include/ncurses.h"
^
/usr/local/Cellar/ncurses/6.1/include/ncurses.h:674:45: error: conflicting types for 'keyname'
extern NCURSES_EXPORT(NCURSES_CONST char *) keyname (int); /* implemented */
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/curses.h:598:45: note: previous declaration is here
extern NCURSES_EXPORT(NCURSES_CONST char *) keyname (int); /* implemented */
...
I'm trying to compile the package using:
swift build -Xcc -I/usr/local/Cellar/ncurses/6.1/include/ -Xlinker -L/usr/local/Cellar/ncurses/6.1/lib
I also went down the route of specifying the pkgConfig
on the package definition, with the same result. Can someone help?
FYI It's worth mentioning that upon ncurses installation through Homebrew I get the following warning as ncurses is already provided by OS X:
ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ncurses first in your PATH run:
echo 'export PATH="/usr/local/opt/ncurses/bin:$PATH"' >> ~/.zshrc
For compilers to find ncurses you may need to set:
export LDFLAGS="-L/usr/local/opt/ncurses/lib"
export CPPFLAGS="-I/usr/local/opt/ncurses/include"
For pkg-config to find ncurses you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ncurses/lib/pkgconfig"
Pkgconfig for ncurses looks like this
# pkg-config file generated by gen-pkgconfig
# vile:makemode
prefix=/usr/local/Cellar/ncurses/6.1
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/ncursesw
abi_version=6
major_version=6
version=6.1.20180127
Name: ncursesw
Description: ncurses 6.1 library
Version: ${version}
URL: https://invisible-island.net/ncurses
Requires.private:
Libs: -L${libdir} -lncursesw
Libs.private:
Cflags: -D_DARWIN_C_SOURCE -I/usr/local/Cellar/ncurses/6.1/include -I${includedir}
/usr/local/opt/ncurses/lib/pkgconfig
file? You likely need other compiler flags to be passed in as well. – ConservatismCflags
andLibs
flags to yourswift build
or modulemap's link command? – Conservatism