我是使用 ncurses 库的新手,所以我一直在尝试重新创建此页面上的一些示例,http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html.
我已经获得了有关创建菜单的部分,特别是示例 21。我编写的程序可以在 Linux(特别是 Ubuntu 18.04)上运行,但是当我使用菜单库时,我无法编译。我使用 JUST ncurses 编写的所有其他示例程序都可以正常编译,没有问题,只是当我尝试使用菜单库时。
我在 Linux 和 macOS 上构建时使用的命令是:
gcc libmenutest.c -o test -lmenu -lncurses
我尝试过移动-lmenu -lncurses
关于并更改 macOS 上的顺序但没有成功。我已经通过brew安装了ncurses并尝试使用brew中的gcc-8,但也没有成功。
我正在运行几乎全新安装的 macOS 和最新的命令行工具。我可以在中看到 libmenu/usr/lib
,与 libncurses 相同。所以我真的很困惑为什么编译器找不到它。
这是我一直试图诊断问题的一些测试代码。
#include <curses.h>
#include <menu.h>
#include <stdlib.h>
#define ARRAY_SIZE(a) (sizeof a / sizeof a[0])
int main (void)
{
int i;
int nchoices;
char *choices[] = {
"Choice 1", "Choice 2", "Choice 3", "Exit", (char *) NULL,
};
// Test that the types are present, this should test for the include headers
ITEM **items;
MENU *menu;
WINDOW *win;
// This will test for includes and to see if libncurses can be linked
initscr ();
noecho ();
cbreak ();
keypad (stdscr, TRUE);
// this bit will test for libmenu include and if it can be linked
nchoices = ARRAY_SIZE (choices);
items = calloc (nchoices, sizeof (ITEM *));
if (items == NULL) exit (1);
for (i = 0; i < nchoices; i++)
items[i] = new_item (choices[i], choices[i]);
// write smarmy message to screen :^^^^^^)
printw ("This worked :^)");
refresh ();
getch ();
// clean up
for (i = 0; i < nchoices; i++)
free_item (items[i]);
endwin ();
return 0;
}
这是我现在得到的输出......
Undefined symbols for architecture x86_64:
"_free_item", referenced from:
_main in libmenutest-0f0c39.o
"_new_item", referenced from:
_main in libmenutest-0f0c39.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)