Makefile文件的编写:
#all : test.c
test : test.c
gcc $^ -o $@ -I/usr/include -L/usr/lib -lncurses
clean :
-rm *.o
注意紫色部分代码,若不添加其代码会出现一下错误信息
gcc test.c -o test
/tmp/ccKYmGQf.o: In function `initial':
test.c:(.text+0x7): undefined reference to `initscr'
test.c:(.text+0xc): undefined reference to `cbreak'
test.c:(.text+0x11): undefined reference to `nonl'
test.c:(.text+0x16): undefined reference to `noecho'
test.c:(.text+0x1b): undefined reference to `stdscr'
test.c:(.text+0x2b): undefined reference to `intrflush'
test.c:(.text+0x30): undefined reference to `stdscr'
test.c:(.text+0x40): undefined reference to `keypad'
test.c:(.text+0x45): undefined reference to `stdscr'
test.c:(.text+0x4d): undefined reference to `wrefresh'
/tmp/ccKYmGQf.o: In function `main':
test.c:(.text+0x78): undefined reference to `stdscr'
test.c:(.text+0xc0): undefined reference to `wborder'
test.c:(.text+0xc5): undefined reference to `stdscr'
test.c:(.text+0xdd): undefined reference to `wattr_on'
test.c:(.text+0xe2): undefined reference to `stdscr'
test.c:(.text+0xfa): undefined reference to `wmove'
test.c:(.text+0x104): undefined reference to `stdscr'
test.c:(.text+0x11c): undefined reference to `waddnstr'
test.c:(.text+0x121): undefined reference to `stdscr'
test.c:(.text+0x139): undefined reference to `wattr_off'
test.c:(.text+0x13f): undefined reference to `stdscr'
test.c:(.text+0x155): undefined reference to `wmove'
test.c:(.text+0x15a): undefined reference to `stdscr'
test.c:(.text+0x162): undefined reference to `wgetch'
test.c:(.text+0x20e): undefined reference to `stdscr'
test.c:(.text+0x224): undefined reference to `wmove'
test.c:(.text+0x22e): undefined reference to `stdscr'
test.c:(.text+0x23e): undefined reference to `waddch'
test.c:(.text+0x245): undefined reference to `endwin'
test.c:(.text+0x25a): undefined reference to `stdscr'
test.c:(.text+0x266): undefined reference to `waddch'
test.c:(.text+0x280): undefined reference to `stdscr'
test.c:(.text+0x296): undefined reference to `wmove'
collect2: ld returned 1 exit status
make: *** [test] Error 1
当出现上述错误信息的时候,需要在Makefile文件中编译的时候添加以下语句
# gcc test.c -o test -I/usr/include -L/usr/lib -lncurses
最后执行./test 即可看到所有执行的结果
