View Full Version : ncurses compilation error
Kimm
March 8th, 2005, 06:51 PM
ok, I just installed ncurses libraries on my computer, I need them for a project for school... when I try to compile this program (just made it to test if g++ found the libraries):
#include <ncurses.h>
int main()
{
getch();
return 0;
}
g++ gives me this error:
/tmp/cclgZLIU.o(.test+0x11): In function 'main':
: undefined reference to 'stdscr'
/tmp/cclgZLIU.o(.test+0x19); In function 'main':
: undefined reference to 'wgetch'
collect2: ld returned 1 exit status
can anyone tell me whats wrong? ](*,)
goatnuts
March 31st, 2005, 03:42 AM
ok, I just installed ncurses libraries on my computer, I need them for a project for school... when I try to compile this program (just made it to test if g++ found the libraries):
#include <ncurses.h>
int main()
{
getch();
return 0;
}
g++ gives me this error:
can anyone tell me whats wrong? ](*,)
You need to add the compiler flag "-lcurses" to tell the compiler to use the curses library. My compiler call looks like this
g++ -o foo/bar foo/c.o foo/main.o -pthread -lwx_gtk2-2.4 -lcurses
Hope this helps.
-goatnuts
ben-g
September 19th, 2006, 05:45 PM
All the other code besides "g++ -o -pthread -lcurses" doesn't work but when I do run that it gives me this error.
"/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../lib/crt1.o: In function `_start':../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status"
I really need to figure this out because it's in my c++ class, so if any of you know how to do this please respond.
po0f
September 19th, 2006, 09:56 PM
How exactly are you calling the compiler? The "-o" flag takes one argument, the target binary, or output. And if you are using ncurses, you need to tell the linker what libraries to link the binary with, namely curses. Something like this should work:
$ gcc -Wall -o mybinary mysource.c -lcurses
The above might not work. If you get linker errors, try substituting "-lncurses" in that case. I don't know if you should be calling initscr() for so simple a program, but that might help too. Also, it'd be a good idea to get used to adding "-Wall" to all your compiler commands, it lets you know when you made a boo-boo.
ben-g
September 20th, 2006, 03:48 AM
I'm rather new to all of this, so if you could tell me what initscr() is that would help. I tried the code you gave me but it says that mysource.c doesn't exist. Do I have some missing files that I should download?
Thank you for helping me I really appreciate it.
po0f
September 20th, 2006, 09:59 AM
If you need some curses help, this (http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html) is what I started to learn. TLDP (http://www.tldp.org/) is a pretty good starting point for almost any Linux-related question, just for future reference.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.