无法在gcc(OS X)上使用curses编译

14

我写了一个“Hello, world”程序来了解curses库的工作原理。

下面是我的程序:

/Users/snihalani/dev/daas at 10:10AM 
➜ cat main.c 
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>

int main(void)
{
    int returnValue = 0;
    while(1)
    {
        printf("I got %d\n", getch());
    }
    return 0;
}

我运行了gcc main.c

我得到了

/Users/snihalani/dev/daas at 10:14AM 
 gcc main.c 
Undefined symbols for architecture x86_64:
  "_stdscr", referenced from:
      _main in ccEvUdhx.o
  "_wgetch", referenced from:
      _main in ccEvUdhx.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

我不知道出了什么问题。请问有人可以帮忙吗?

1个回答

28

没事了,我在编译时需要加上-lcurses选项。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接