0

I'm trying to compile a program using both curses and menu on Cion on MacOS Ventura.

I use this simple code as test


#include <menu.h>
#include <stdio.h>
#include <stdlib.h>

int cols, lines;

int main(int argc, char *argv[]) {

     initscr();

     getmaxyx(stdsrc, lines, cols);

     noecho();
     nocbreak();
     keypad(stdscr, TRUE);

    MENU* my_test_menu = new_menu(NULL);

    getch();

    exit(EXIT_SUCCESS);

}

When compiling using the following CMake configuration


...
find_package(Curses REQUIRED)

include_directories(${CURSES_INCLUDE_DIR})

...

target_link_libraries(my_projet PRIVATE menu ${CURSES_LIBRARY})

I got the following error from the linker :

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 have tested that build configuration on ubuntu AMD64 without any issue.

Solution using brew and MacPort like this one doesn't interest me because I would have to manually point CMake to the include dir in my CMake setup, preventing the build from being "universal".

Also, after further testing curses panel and form work perfectly when included. So, I'm begun to suspect an issue with MacOS menu.

My point is also why would the system include the header file and not the actual library, which seems pretty mind blowing.

Hope someone have a solution or at least an explanation and have a nice day.

Shalien
  • 49
  • 6
  • 1
    Does `include_directories(${CURSES_INCLUDE_DIR})` after `find_package(Curses REQUIRED)` helps? – David Ranieri Feb 28 '23 at 11:16
  • I had that line in my CMake already and it doesn't help. But I tested using ncurses form and panel and including them and ... they work. So I'm beginning to think I have found a MacOS bug. – Shalien Feb 28 '23 at 13:06
  • 1
    What if you use `CURSES_LIBRARIES` instead of `CURSES_LIBRARY`? [The docs say](https://cmake.org/cmake/help/latest/module/FindCurses.html#backward-compatibility) `CURSES_LIBRARY` is for backwards compatibility and `CURSES_LIBRARIES` should be used instead. How did you install curses? Or is it on your machine out-of-box? – starball Feb 28 '23 at 17:01

1 Answers1

1

After opening the issue on the Apple Developer Forum, this is caused by a bug with the exported symbol for the ncurses library in the MacOS SDK.

A link to said thread: https://developer.apple.com/forums/thread/725710

As a workaround the following steps can be followed: 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.

Shalien
  • 49
  • 6