Ir ao conteúdo
  • Cadastre-se

Eu não consigo programar em nCurses (Ubuntu Linux 17.04)


Lerub

Posts recomendados

Há meses que eu tento programar com as libs nCurses, mas eu não estou me dando muito bem com isso.

 

O código que eu tentei compilar, dessa vez, é esse:

 


#include <stdlib.h>
#include <curses.h>
#include <signal.h>

static void finish(int sig);

int
main(int argc, char *argv[])
{
    int num = 0;


    (void) signal(SIGINT, finish);      

    (void) initscr();     
    keypad(stdscr, TRUE);
    (void) nonl();        
    (void) cbreak();      
    (void) echo();         

    if (has_colors())
    {
        start_color();

        init_pair(1, COLOR_RED,     COLOR_BLACK);
        init_pair(2, COLOR_GREEN,   COLOR_BLACK);
        init_pair(3, COLOR_YELLOW,  COLOR_BLACK);
        init_pair(4, COLOR_BLUE,    COLOR_BLACK);
        init_pair(5, COLOR_CYAN,    COLOR_BLACK);
        init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
        init_pair(7, COLOR_WHITE,   COLOR_BLACK);
    }

    for (;;)
    {
        int c = getch();     
        attrset(COLOR_PAIR(num % 8));
        num++;

    }

    finish(0);
}

static void finish(int sig)
{
    endwin();

    exit(0);
}

 

Desse tutorial:

 

Para compilar:

gcc -lncurses

 

Saida do comando:

Citação

/tmp/cczryhqq.o: In function `main':
curseslibexperiment.c:(.text+0x28): undefined reference to `initscr'
curseslibexperiment.c:(.text+0x2f): undefined reference to `stdscr'
curseslibexperiment.c:(.text+0x3c): undefined reference to `keypad'
curseslibexperiment.c:(.text+0x41): undefined reference to `nonl'
curseslibexperiment.c:(.text+0x46): undefined reference to `cbreak'
curseslibexperiment.c:(.text+0x4b): undefined reference to `echo'
curseslibexperiment.c:(.text+0x50): undefined reference to `has_colors'
curseslibexperiment.c:(.text+0x5d): undefined reference to `start_color'
curseslibexperiment.c:(.text+0x71): undefined reference to `init_pair'
curseslibexperiment.c:(.text+0x85): undefined reference to `init_pair'
curseslibexperiment.c:(.text+0x99): undefined reference to `init_pair'
curseslibexperiment.c:(.text+0xad): undefined reference to `init_pair'
curseslibexperiment.c:(.text+0xc1): undefined reference to `init_pair'
/tmp/cczryhqq.o:curseslibexperiment.c:(.text+0xd5): more undefined references to `init_pair' follow
/tmp/cczryhqq.o: In function `main':
curseslibexperiment.c:(.text+0xf0): undefined reference to `stdscr'
curseslibexperiment.c:(.text+0xf8): undefined reference to `wgetch'
curseslibexperiment.c:(.text+0x102): undefined reference to `stdscr'
curseslibexperiment.c:(.text+0x10e): undefined reference to `stdscr'
/tmp/cczryhqq.o: In function `finish':
curseslibexperiment.c:(.text+0x13c): undefined reference to `endwin'
collect2: error: ld returned 1 exit status

 

Eu já tentei até retirar os parenteses dos "void" e nada. Eu baixei as lib "libcurses", "libncurses" e todas as outras pelo "apt-get".

Link para o comentário
Compartilhar em outros sites

  • Membro VIP

Opa,

 

Você precisa instalar o pacote libncurses-dev, que tem a curses.h. E faltou informar para o gcc o nome do seu programa (do seu arquivo .c):

$ sudo apt-get install libncurses-dev
$ gcc -o lerub lerub.c -lncurses

Em tempo, é bom se acostumar a usar as opções -W e -Wall do gcc pra ver se tem mais erros no programa. Veja:

$ gcc -W -Wall -o lerub lerub.c -lncurses
lerub.c: In function ‘main’:
lerub.c:36:59: warning: unused variable ‘c’ [-Wunused-variable]
                                                       int c = getch();
                                                           ^
lerub.c:8:10: warning: unused parameter ‘argc’ [-Wunused-parameter]
 main(int argc, char *argv[])
          ^
lerub.c:8:22: warning: unused parameter ‘argv’ [-Wunused-parameter]
 main(int argc, char *argv[])
                      ^
lerub.c: In function ‘finish’:
lerub.c:45:24: warning: unused parameter ‘sig’ [-Wunused-parameter]
 static void finish(int sig)
                        ^

Tem várias variáveis não utilizadas em seu código. Se você ainda tiver desenvolvendo e for utilizá-las mais tarde, tudo bem, mas se não, pode removê-las. :-)

 

Abraços!

 

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...