Undefined symbols for architecture x86_64 with ncurses

The following program fails to compile at linking time with the undefined symbol error for symbols _getmaxx and _stdscr:

import Darwin.ncurses

let maxx = getmaxx(stdscr)

My environment: Xcode 11.3.1 (11C504) on macOS 10.15.2 (19C57). Nothing else fancy, just running a swift run in a package generated by SPM with the “executable” type, and a single main.swift source file containing the code above.

Anybody has any idea what’s going on and how to fix this?

Thanks

EDIT:

Adding the -Xlinker -lncurses options solves the compilation. I still don’t know why it does not work out of the box. Is this a bug? Should I report it?

I don't think it's bug, just part of doing business on Darwin (maybe Linux). NCurses is a library in /usr/lib, but, there are lot of other libraries as well. The "import" directive only gets you the module map, the linker (ld), which is separate from the compiler, needs to link in the object code for library to build the executable. The "-lncurses" is a directive to the linker to load the library object code.

You’ll be better off adding it properly. Have a look at how swift-llbuild declares its use of ncurses.

1 Like

This is what I didn’t know I was searching for. Thanks!

Terms of Service

Privacy Policy

Cookie Policy