对“initscr"Ncurses 的未定义引用 [英] Undefined reference to `initscr' Ncurses
本文介绍了对“initscr"Ncurses 的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编译我的项目并使用 lib ncurse.当编译器链接文件时,我遇到了一些错误.
I'm trying to compile my project and I use the lib ncurse. And I've got some errors when compiler links files.
这是我在 Makefile 中的标志行:
Here is my flags line in Makefile:
-W -Wall -Werror -Wextra -lncurses
我已经包含了 ncurses.h
I've included ncurses.h
一些布局:
prompt$> dpkg -S curses.h
libslang2-dev:amd64: /usr/include/slcurses.h
libncurses5-dev: /usr/include/ncurses.h
libncurses5-dev: /usr/include/curses.h
prompt$> dpkg -L libncurses5-dev | grep .so
/usr/lib/x86_64-linux-gnu/libncurses.so
/usr/lib/x86_64-linux-gnu/libcurses.so
/usr/lib/x86_64-linux-gnu/libmenu.so
/usr/lib/x86_64-linux-gnu/libform.so
/usr/lib/x86_64-linux-gnu/libpanel.s
这是我的错误:
gcc -W -Wall -Werror -Wextra -I./Includes/. -lncurses -o Sources/NCurses/ncurses_init.o -c Sources/NCurses/ncurses_init.c
./Sources/NCurses/ncurses_init.o: In function `ncruses_destroy':
ncurses_init.c:(.text+0x5): undefined reference to `endwin'
./Sources/NCurses/ncurses_init.o: In function `ncurses_write_line':
ncurses_init.c:(.text+0xc5): undefined reference to `mvwprintw'
./Sources/NCurses/ncurses_init.o: In function `ncurses_init':
ncurses_init.c:(.text+0xee): undefined reference to `initscr'
collect2: error: ld returned 1 exit status
非常感谢
推荐答案
您需要更改您的 makefile,以便 -lncurses
指令出现在您的目标代码之后gcc命令行,即需要生成命令:
You need to change your makefile so that the -lncurses
directive comes after your object code on the gcc command line, i.e. it needs to generate the command:
gcc -W -Wall -Werror -Wextra -I./Includes/. -o Sources/NCurses/ncurses_init.o -c Sources/NCurses/ncurses_init.c -lncurses
这是因为目标文件和库在一次传递中按顺序链接.
This is because object files and libraries are linked in order in a single pass.
这篇关于对“initscr"Ncurses 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文