Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to `initscr' Ncurses

Tags:

I'm trying to compile my project and I use the lib ncurse. And I've got some errors when compiler links files.

Here is my flags line in Makefile:

-W -Wall -Werror -Wextra -lncurses 

I've included ncurses.h

Some layouts :

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 

And here are my erros :

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 

Thanks a lot

like image 406
BoilingLime Avatar asked Apr 24 '13 12:04

BoilingLime


1 Answers

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.

like image 191
Paul R Avatar answered Sep 21 '22 17:09

Paul R