Hello everyone,
I'm fairly new to C/C++ development on MacOS / iOS and I tried to build a test project using the curses library.
However, I was faced with an issue regarding the linking of libmenu / menu.h related functions.
When I tried to build my project, I get the following error from clang:
Undefined symbol for architecture arm64 :
"_new_menu" referenced from my_file.cpp
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1
I tried to include both libncruses.tdb and libmenu.tdb to my project but to no avail.
Searching online I also found a lot of people using libmenu from either brew or macports but since the library already exists on the system, I would rather depend on that one instead of having to customize my build pipeline to gather elements from extra include path .
So is there a solution to use the system libmenu / menu.h or I doomed to install macports ?
AFAICT this problem is caused by a bug in the macOS SDK. Before going further, please read An Apple Library Primer because I’m going to assume terms from that.
If you open the libmenu.5.4.tbd stub library you’ll find that it has nothing in the exports section:
compatibility-version: 5.4
...
Contrast this with, say, libncurses.5.4.tbd:
compatibility-version: 5.4
exports:
- targets: [ x86_64-macos, x86_64-maccatalyst, arm64-macos, arm64-maccatalyst,
arm64e-macos, arm64e-maccatalyst ]
symbols: [ _BC, … and lots more… ]
...
Grepping the entire lib directory reveals no stub library with a reference to _new_menu (the leading _ implies a C symbol, rather than an assembly language one). AFAICT these symbols are just not exported.
This is clearly a bug and I encourage you to file it as such. Please post your bug number, just for the record.
As to a workaround, what you can do is copy libmenu.5.4.tbd and add the exports you need. For example, I named by copy libmenu-q.tbd and edited the end of it to look like this:
compatibility-version: 5.4
exports:
- targets: [ x86_64-macos, arm64-macos, arm64e-macos ]
symbols: [ _new_menu ]
...
I added that to my project and made sure it was listed in the General > Frameworks and Libraries list. With that done, I was able to link and call the routine. So the symbol is being exported at runtime, it’s just missing from the stub library.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"