Solved

ncurses in netbeans with cygwin compiler

Posted on 2010-09-07
2
1,818 Views
Last Modified: 2013-11-15
I'm trying to run this C code in netbeans 6.8. I have installed cygwin gcc compiler. At compilation I get these error messages:

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest'
/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/cursestest.exe
make[2]: Entering directory `/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest'
mkdir -p build/Debug/Cygwin-Windows
rm -f build/Debug/Cygwin-Windows/main.o.d
gcc    -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/main.o.d -o build/Debug/Cygwin-Windows/main.o main.c
main.c:47:2: warning: no newline at end of file
mkdir -p dist/Debug/Cygwin-Windows
gcc     -o dist/Debug/Cygwin-Windows/cursestest build/Debug/Cygwin-Windows/main.o  
build/Debug/Cygwin-Windows/main.o: In function `draw':
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:13: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:13: undefined reference to `_wmove'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:14: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:14: undefined reference to `_wdelch'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:14: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:14: undefined reference to `_winsch'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:15: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:15: undefined reference to `_wrefresh'
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:30: undefined reference to `_initscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:31: undefined reference to `_cbreak'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:32: undefined reference to `_noecho'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:34: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:34: undefined reference to `_wclear'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:35: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:35: undefined reference to `_wrefresh'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:39: undefined reference to `_stdscr'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:39: undefined reference to `_wgetch'
/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest/main.c:44: undefined reference to `_endwin'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/cursestest.exe] Error 1
make[2]: Leaving directory `/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/cygdrive/c/Documents and Settings/stefano federici/Documenti/NetBeansProjects/cursestest'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 8s)
// simple curses example; keeps drawing the inputted characters, in columns
 // downward, shifting rightward when the last row is reached, and
 // wrapping around when the rightmost column is reached

 #include "ncurses\curses.h" // required

 int r,c, // current row and column (upper-left is (0,0))
 nrows, // number of rows in window
 ncols; // number of columns in window

 void draw(char dc)

 { move(r,c); // curses call to move cursor to row r, column c
 delch(); insch(dc); // curses calls to replace character under cursor by dc
 refresh(); // curses call to update screen
 r++; // go to next row
 // check for need to shift right or wrap around
 if (r == nrows) {
 r = 0;
 c++;
 if (c == ncols) c = 0;
 }
 }

 main()

 { int i; char d;
 WINDOW *wnd;

 wnd = initscr(); // curses call to initialize window
 cbreak(); // curses call to set no waiting for Enter key
 noecho(); // curses call to set no echoing
 getmaxyx(wnd,nrows,ncols); // curses call to find size of window
 clear(); // curses call to clear screen, send cursor to position (0,0)
 refresh(); // curses call to implement all changes since last refresh

 r = 0; c = 0;
 while (1) {
 d = getch(); // curses call to input from keyboard
 if (d == 'q') break; // quit?
 draw(d); // draw the character
 }

 endwin(); // curses call to restore the original window and leave

 }

Open in new window

0
Comment
Question by:Esanteva
2 Comments
 
LVL 13

Accepted Solution

by:
Superdave earned 500 total points
ID: 33621960
Judging by this line of output:

gcc     -o dist/Debug/Cygwin-Windows/cursestest build/Debug/Cygwin-Windows/main.o  

you don't have any libraries specified in the makefile.  You'll need to add at least -lncurses to that command.
0
 

Author Closing Comment

by:Esanteva
ID: 33622179
I don't know what happened: following direction I found on the web I had added the -lncurses option for libraries. But then, you are perfectly right, now it was missing. So... Thanks.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A list of useful business intelligence software.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question