PDA

View Full Version : Help using Ncurses



Yes
September 10th, 2007, 10:52 PM
Well, I'm trying to teach myself how to use the Ncurses library, but I'm already having trouble with the Hello World program. When I try running it, I get these errors:

http://harrypottermovie7.com/upload/images/cqs1189458956c.png

I have no idea what that means...the "multiple definitions" seems sorta like I have multiple versions of Ncurses installed, and they're conflicting with each other, but that's just an uneducated guess. So, does anyone know what my problem might be?

Thanks.

slavik
September 11th, 2007, 12:00 AM
post the code please (surrounded by code tags)

Wybiral
September 11th, 2007, 01:10 AM
Yeah, if you post the code and the command you are using to compile it then we can definitely help figure out whats wrong.

Yes
September 11th, 2007, 02:49 AM
#include <iostream>

#include <cstdlib>

#include <ncurses.h>

using namespace std;

int main()
{
initscr();
printw("Hello World !!!");
refresh();
getch();
endwin();

return 0;
}

Yes
September 11th, 2007, 10:07 PM
The guide I'm using is written for C, and I'm using C++, would that be my problem?

robdor
September 11th, 2007, 11:38 PM
No, that shouldn't be a problem. What is the command that you are using the compile it? I used the command below to compile and everything worked as expected.


g++ -lncurses -o test ncurses_test.cpp

Yes
September 12th, 2007, 12:38 AM
My build command is


g++ -Wall -lncurses -o "%f"

where "%f" is replaced with the file name. Now I get these build errors:


/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

xtacocorex
September 12th, 2007, 01:07 AM
Don't think you need the cstdlib.h in your includes.

Yes
September 12th, 2007, 01:20 AM
Yeah, I know. But that's not what's causing the errors.

dwhitney67
September 12th, 2007, 05:58 AM
My build command is


g++ -Wall -lncurses -o "%f"

where "%f" is replaced with the file name. Now I get these build errors:


/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

xtacocorex is right, you do not need to include cstdlib.h.

Aside from that, I tried your program on my system and it compiles and runs fine. I compiled using:

g++ -Wall ncurses.cpp -lncurses

Then I ran "a.out".

You may want to consider re-installing "build-essentials".

Lux Perpetua
September 13th, 2007, 07:50 AM
My build command is


g++ -Wall -lncurses -o "%f"

where "%f" is replaced with the file name. Now I get these build errors:


/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

You're probably just forgetting to specify a source file. "-o file.cpp" means the compiled executable is to be called file.cpp, not that you want to compile file.cpp. Fixing that should fix your problem.

Yes
September 13th, 2007, 10:37 PM
Ugh, I'm an idiot. I had my execute arguments screwed up. Thank's, it's all sorted out now.