installation of ncurses

Asked by prasad.ram

i use the command for installing ncurses library which is given by you

admin@ramki:~$ sudo apt-get install ncurses-dev
[sudo] password for admin:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libncurses5-dev' instead of 'ncurses-dev'
libncurses5-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 314 not upgraded.
that means it is already installed
and i do a basic "hello world "program and the code is
#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;
}

i compiled using gnu compiler and command is gcc filename
and it gives that
#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;
}
and i would like to know what is the fault is installation or in program if in installation please tell me how it could be?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
mycae (mycae) said :
#1

can you review your question -- you appear to have cut and pasted your code twice.

I assume you are compiling your code with gcc like

gcc main.cpp -o main

if so, you need to "link" against the ncurses library like so

gcc main.cpp -o main -lncurses

(possibly -lcurses -- I am on a different machine right now)

Remember your compile & link phases are separate in gcc:
https://secure.wikimedia.org/wikipedia/en/wiki/Linker_%28computing%29

Revision history for this message
prasad.ram (prasad-ram126) said :
#2

this is my command
gcc main.c
and yes sir i recognise that i did not link lcurses library
if i link that library it executes i would like to know what is the
necessity i already link that in my code through #include<ncurses.h> and
if i write a normal c program i did not link any libraries like standard
libraries ?
and another question that is there any process to do without link these
libraries for every time ?

On Tue, Mar 22, 2011 at 9:19 PM, mycae <<email address hidden>
> wrote:

> Your question #150042 on gcc-defaults in Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/150042
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> can you review your question -- you appear to have cut and pasted your
> code twice.
>
> I assume you are compiling your code with gcc like
>
> gcc main.cpp -o main
>
> if so, you need to "link" against the ncurses library like so
>
> gcc main.cpp -o main -lncurses
>
>
> (possibly -lcurses -- I am on a different machine right now)
>
> Remember your compile & link phases are separate in gcc:
> https://secure.wikimedia.org/wikipedia/en/wiki/Linker_%28computing%29
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/150042/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/150042
>
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
mycae (mycae) said :
#3

>#include<ncurses.h>

This is not a linker command; this is a preprocessor directive. Your linker will never see this. Its essentially asking the preprocessor (which happens before compilation!) to cut and paste the contents of that file at this location. Have a play with gcc's -E option (stop after preprocessing) to understand.

>did not link any libraries like standard libraries

the standard libraries, being standard, are linked implicitly.

>without link these libraries for every time ?
No. You have to link at every time.

You can simplify your build command (and save typing) by using Makefiles
https://secure.wikimedia.org/wikipedia/en/wiki/Makefiles

Can you help with this problem?

Provide an answer of your own, or ask prasad.ram for more information if necessary.

To post a message you must log in.