0

I have looked at similar question on this site and googled why this is happening but have tried these solutionnot able to compile, difference between ncurses and curses, another compile error, but I am still having the problem with the error undefined reference to stdscr and wgetch the compiler is finding the library as far as I can figure out as I used find to locate the curses library and entered the full location in the #include line.

my code is as follows

#include <ncurses.h>
#include <stdio.h>
#include <string.h>

int first_line(char);
int main(){

    char c = 0;

    while((c = getch())!=EOF){
        first_line(c);

    }   

    return 0;
}

int first_line(char c){
    if (c != '\n' && c != '\r'){
            putchar(c);
        do{
            c = getch();
            putchar(c);}
            while( c !='\n');

    }
    else return 0;

    return 0;
}

If you can point to what I've missed or am doing wrong I would much appreciate it.

Community
  • 1
  • 1
UNECS
  • 533
  • 1
  • 9
  • 20

1 Answers1

2

ncurses.h is a header file (containing declarations), not a library (containing code that implements those declarations).

The error message you're seeing is from the linker, not from the compiler.

If you're using gcc, you need to add either -lcurses or -lncurses to the compiler command line (after your source file name).

For example, on my system I copied your source to c.c, and I can compile and link it using either

gcc c.c -o c -lcurses

or

gcc c.c -o c -lncurses
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631