Can't compile with ncurses in Opensuse 12.2?

Hi all,

For some reason if I try to compile a simple terminal program in c++ with ncurses in Opensuse 12.2, I keep getting errors?

Here are the ncurses packages I have installed:

yast2-ncurses-pkg-2.22.7-2.1.2.i586
libncurses5-5.9-12.5.1.i586 <— 1
ncurses-utils-5.9-12.5.1.i586
ncurses-devel-5.9-12.5.1.i586
libncurses6-5.9-12.5.1.i586 <— 2?
yast2-ncurses-2.22.4-1.1.2.i586

I don’t know why I have 2 lots of libncurses installed, the packages came when I installed the system.

Here is the small program I want to compile as a test of ncurses working:

#include <ncurses.h>

int main()
{
initscr(); // Start curses mode
printw(“Hello World !!!”); // Print Hello World
refresh(); // Print it on to the real screen
getch(); // Wait for user input
endwin(); // End curses mode

    return 0;

}

Here are the errors:

/usr/lib/gcc/i586-suse-linux/4.7/…/…/…/…/i586-suse-linux/bin/ld: /lib/libncurses.so.5: undefined reference to symbol ‘stdscr’
/usr/lib/gcc/i586-suse-linux/4.7/…/…/…/…/i586-suse-linux/bin/ld: note: ‘stdscr’ is defined in DSO /usr/lib/gcc/i586-suse-linux/4.7/…/…/…/libtinfo.so so try adding it to the linker command line
/usr/lib/gcc/i586-suse-linux/4.7/…/…/…/libtinfo.so: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

Any ideas, this stuff normally just works? Thanks for any help.

  1. there is a Prigramming/Scripting subforum here. Why didn’t you aks there? Do you want me to move this?

  2. please use CODE tags arounf all the computer text you post here with copy/past. Use the # button the tool bar of the editor.

welcome new poster!

> Here are the ncurses packages I have installed:
>
> yast2-ncurses-pkg-2.22.7-2.1.2.i586
> libncurses5-5.9-12.5.1.i586 <— 1
> ncurses-utils-5.9-12.5.1.i586
> ncurses-devel-5.9-12.5.1.i586
> libncurses6-5.9-12.5.1.i586 <— 2?
> yast2-ncurses-2.22.4-1.1.2.i586

please tell us how you came up with that list? (from a terminal command,
maybe? if so, instead of typing a story, show us the terminal output
and input, from prompt, command, to output and next prompt…and,
copy/paste it all back to this thread using the instructions here:
http://goo.gl/i3wnr

and, then please notice that we have a programming forum and you should
be using it (that is one place you can expect the programming gurus to
hang out–they may be in Applications also, but.)…so, please press
the “Report” button on this post and ask a moderator to move this thread
to http://tinyurl.com/5v695w4


dd http://goo.gl/PUjnL

/usr/bin/g++ -O2 -g -Wall -lncurses -o ncurses ncurses.cpp

Works here.

Hi all,

For some reason if I try to compile a simple terminal program in c++ with ncurses in Opensuse 12.2, I keep getting errors?

I am using the command line:

g++ -g -Wall -lncurses ncurses.cpp -o ncurses

Here are the ncurses packages I have installed (found with rpm -qa > pkglist):

yast2-ncurses-pkg-2.22.7-2.1.2.i586
libncurses5-5.9-12.5.1.i586
ncurses-utils-5.9-12.5.1.i586
ncurses-devel-5.9-12.5.1.i586
libncurses6-5.9-12.5.1.i586
yast2-ncurses-2.22.4-1.1.2.i586

Here is the small program I want to compile as a test of ncurses working:


#include <ncurses.h>

int main()
{       
        initscr();                        // Start curses mode
        printw("Hello World !!!");   // Print Hello World
        refresh();                      // Print it on to the real screen
        getch();                        // Wait for user input
        endwin();                       // End curses mode

        return 0;
}

Here are the errors:

/usr/lib/gcc/i586-suse-linux/4.7/…/…/…/…/i586-suse-linux/bin/ld: /lib/libncurses.so.5: undefined reference to symbol ‘stdscr’
/usr/lib/gcc/i586-suse-linux/4.7/…/…/…/…/i586-suse-linux/bin/ld: note: ‘stdscr’ is defined in DSO /usr/lib/gcc/i586-suse-linux/4.7/…/…/…/libtinfo.so so try adding it to the linker command line
/usr/lib/gcc/i586-suse-linux/4.7/…/…/…/libtinfo.so: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

Any ideas, this stuff normally just works? Thanks for any help.

Thanks guys, I have used the ‘programming’ sub-forum as requested, didn’t even see it.

Nightwishfan, I used the same command line as you and got those errors.

I found the rpms installed by using:

rpm -qa > pkglist.txt
grep ncurses pkglist.txt

@londondaveuk,

People suggested you to ask for your thread moved to the Progrtamming/Scripting forum. You did not.
Instead you doubleposted. This will most probably create a mess because now people are going to answer either here or there without knowing what others already posted.

I will now merge these two threads.

Everybody please wait until merging is complete.

There is now a double post. Sigh …

This thread is closed and will be merged with the other one.

Please refrain from posting until complete.

This is now merged. Open for bussiness.

As asked, please show prompt, command, output and next prompt. Then you do not have to tell a story on how you did it.

rpm -qa | grep ncurses

I am on 64-bit. So I tested compiling it as a 32-bit executable and it works as well. So I do not know what is wrong. Perhaps reinstall the ncurses and gcc packages? Also you might want to make sure the entire base development pattern is installed.

On 12/13/2012 08:26 PM, hcvv wrote:
> As asked, please show prompt, command, output and next prompt. Then you
> do not have to tell a story on how you did it.

heh…now that i spend the extra seconds needed to look carefully at
what was posted the first time, i see

libncurses5-5.9-12.5.1.i586 <— 1
libncurses6-5.9-12.5.1.i586 <— 2?

and, had i first noted earlier a five became a six, i would not have
wondered what was wrong with his list and asked for a prompt to prompt
paste back…in order to try to solve that riddle.

sorry.

next: the OP speaks of compiling and i think someone needs to look at
the command line entries there also, as well as actual output, prompt to
prompt.


dd

Hi all finally solved. Don’t know how nightwishfan compiled with the above command line on a 32bit system-it will only work if you add

...-ltinfo...

For some reason the linker needs all non-standard libs declared?

But thanks for all the help.:shame:

Yes, I found that odd that it needed to be declared. However my command did work, so perhaps it is just different on 32bit.