Solved

ncurses in netbeans with cygwin compiler

Posted on 2010-09-07
2
1,794 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If your app took Google’s lash recently, here are the 5 most likely reasons.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now