gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Help with Curses?

#43728 - Faluzure - Thu May 26, 2005 1:04 am

Hello.
Its been a good 2 months since the last time ive programmed, so I thought id play around with some of this GBA stuff. So far, I've grabbed the PDcurses install, copied the .h files to my include directory (I am using devcpp) and have written the following basic program(which should work)

#include <stdio.h>
#include <curses.h>

int main()
{
WINDOW *mywindow;

mywindow = initscr();

return 0;
}

However, I get a linker error, stating that there is an undefined reference to initscr.

Any help would be nice.
Thanks in advance.
Joe

#43740 - tepples - Thu May 26, 2005 3:32 am

You need to specify the pdcurses library when linking.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43809 - Faluzure - Thu May 26, 2005 11:37 pm

Can you elabourate on this procedure, it can clearly find the file, as I only get a Linker error relating to this file, as opposed to compiler errors if i do not include the curses.h file.

#43812 - josath - Thu May 26, 2005 11:46 pm

if you are doing it on the command line, when linking you need to add a -l option with the library (something like -lcurses or -lpdcurses depending on what the name is.) If you are using some sort of IDE then you need to add the curses library to the linking options. I don't know how devcpp works exactly.

#43861 - sgeos - Fri May 27, 2005 11:06 am

What compiler are you using? I don't bother storing the return value of initscr(). I've never had to use it. Always call endwin() before exiting the program. curses.h includes stdio.h. Try compiling this:
Code:
/*** gcc compile options
 *
gcc -Wall -o hellocurses hellocurses.c -lcurses
 */

#include <curses.h>

void message(int p_y, int p_x)
{
        mvprintw(p_y + 0, p_x, "Hello World!");
        mvprintw(p_y + 1, p_x, "Press any key to quit.");
}

void press_any_key(void)
{
        while (ERR == getch())
                /* Keep looping */;
}

int main(void)
{
        int y = 3;
        int x = 3;

        initscr();
        message(y, x);
        press_any_key();
        endwin();
        return (0);
}


I learned basically everything I know about curses fromthis tutorial.

-Brendan

#44001 - Faluzure - Sun May 29, 2005 1:39 am

Well, I tried the program you gave me. Now I get a linker error for just about every required function. I tried Devcpp beta 5, and I get the same problems. I cant find the linker options anywhere which specifies where i can include files. If anyone has any experience with dev-cpp, Id appreciate any help.

#44002 - Faluzure - Sun May 29, 2005 1:54 am

I think I figured out some of the problem, I did not install any of the lib files. I have done so now, but I still get the same errors.

#44029 - Faluzure - Sun May 29, 2005 5:32 pm

Ok, I have finally figured it out. I assumed that it would automatically recignize the .a files I copied into the lib folder. After talking with my lab professer, I found out I had to add the file locations into the further library and linker options, which I guess was mentioned earlier.

Thanks Guys

#44753 - sgeos - Sun Jun 05, 2005 1:55 am

No problem. Good luck!

-Brendan