Pelles C forum

C language => Beginner questions => Topic started by: Paolo_R on June 20, 2009, 08:15:55 AM

Title: Console Applications
Post by: Paolo_R on June 20, 2009, 08:15:55 AM
I want to develop console applications and was wondering whether I can use Pelles C with a library like curses/ncurses/pdcurses (or any other free libraries supporting text mode windowing-type interfaces.)

If so, how would I set up Pelles C to recognise the libraries and include them in compilation?

Are there any such libraries available that I could use with Pelles C?

Thanks
Title: Re: Console Applications
Post by: Romashka on June 20, 2009, 02:06:40 PM
In Project Options dialog add paths to *.lib and *.h of the required libraries on Folders tab, and add the required .lib file on Linker tab,
and of course #include the required headers in your C source code.
I don't know if any of *curses libraries are usable on Windows.
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 03:22:05 AM
Romashka: thank you for the reply. I have found PDcurses (public domain) which comes with .c source code. It also comes with .o files and 2 libraries - panel.a and pdcurses.a, each of which contains the .o files. These are supposed to work under any x 86 architecture.There are no .h files.

I tried compiling the small test program (that came with the package) with BCC5.5 but received a lot of 'unresolved external' errors which I guess is due to the fact that I was unable to #include <curses.h>

Is there any way I could build the libraries under Pelles C and somehow extract the required .h files?

Thanks
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 04:51:06 AM
Forget my previous post! I have found the .h files - but I still get the 'unresolved external' errors.
Title: Re: Console Applications
Post by: Robert on June 21, 2009, 05:41:28 AM
.o and .a libraries are for Linux. You have to build the library for Windows.

Robert Wishlaw
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 05:50:47 AM
Robert:yes, I am now realising that! However, I don't know how to build the library for Windows - I've never built a library before. Any clues - or even solutions - would help!!
Title: Re: Console Applications
Post by: Romashka on June 21, 2009, 11:13:57 AM
Well, the easiest way to try is New -> Project -> Win32 Static library (LIB) then add all .c files from PDCurses to it and then build it.
This way you will get a static library which means every application you link with it will have it embedded in the .exe.

Creating a DLL is more complex becase of __declspec(dllimport/dllexport) crap, and it depends if the library already supports DLL building or you have to add it by yourself.
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 11:40:10 AM
Romashka: thx. I have no idea about the  "__declspec(dllimport/dllexport) crap" but I'll give it a go tomorrow.
Title: Re: Console Applications
Post by: nicolas.sitbon on June 21, 2009, 12:20:49 PM
Don't waste your time, take directly the Windows version of pdcurses  ;)
http://sourceforge.net/project/downloading.php?groupname=gnuwin32&filename=pdcurses-2.6.exe&use_mirror=freefr (http://sourceforge.net/project/downloading.php?groupname=gnuwin32&filename=pdcurses-2.6.exe&use_mirror=freefr)
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 01:04:39 PM
Nicolas: thanks. I have downloaded the file.

Which lib would I use with Pelles C? In the GnuWin\lib directory there are the following files:

curses.dll.a
curses.lib
curses-bcc.lib
libcurses.a
libpanel.a

In the GnuWin\bin directory there is also curses2.dll. What is the purpose of this?

Title: Re: Console Applications
Post by: nicolas.sitbon on June 21, 2009, 02:04:54 PM
I'm sorry, bad link.
Here is the way:
- download pdcurses for Win32 from : http://sourceforge.net/project/downloading.php?group_id=30480&filename=pdc34dllw.zip&a=65239577 (http://sourceforge.net/project/downloading.php?group_id=30480&filename=pdc34dllw.zip&a=65239577)
- extract it
- put *.h in "C:\Program Files\PellesC\Include"
- put pdcurses.lib in "C:\Program Files\PellesC\Lib"
- put pdcurses.dll in "C:\Program Files\PellesC\bin"

test:
Code: [Select]
#pragma comment(lib, "pdcurses.lib")
#include <curses.h>

int main(void)
{
   initscr();
   printw("Hello World !!!\n");
   refresh();
   getch();
   endwin();

   return 0;
}

enjoy!
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 10:34:29 PM
Nicolas: thank you. The test program compiles and executes fine.

However I get a (linking ?) warning:

C:\Program Files\PellesC\Include\curses.h(345): warning #2016: Extended attribute 'dllimport' requires option /Ze; ignored.

What does this mean and how do I eliminate it?

Also why do I need to add the line:

#pragma comment(lib, "pdcurses.lib")

Thanks for your help.


Title: Re: Console Applications
Post by: nicolas.sitbon on June 21, 2009, 11:23:38 PM
In order to suppress the warning, go to Project -> Project Options -> Compiler -> check "Enable Microsoft extensions"
and if you want explanation on that, see this site : http://msdn.microsoft.com/en-us/library/dabb5z75.aspx (http://msdn.microsoft.com/en-us/library/dabb5z75.aspx)

About the pragma comment directive, it's a compiler hint, that says, hey guyz, link me with pdcurses, see http://msdn.microsoft.com/en-us/library/d9x1s805(VS.71).aspx (http://msdn.microsoft.com/en-us/library/d9x1s805(VS.71).aspx).
You can safely remove it, and go to Project -> Project Options -> Linker -> add pdcurses.lib in "Library and object files".

Bye.
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 11:39:14 PM
Nicolas: thanks again.

One comment, I have tried building some of the demo programs that came with the GnuWin version. Some wouldn't run 'cos they couldn't 'find' pdcurses.dll, so I put a copy in my windows/system32 folder and that solved that problem. Why do I need to do this if Pelles C compiler already has a copy in its /bin folder?

A couple of the other demos just hang with a blank screen and flashing cursor. Not sure why if the code is 'common' to all pdcurses platform versions. Something to do with platform-specific #defines?

Title: Re: Console Applications
Post by: nicolas.sitbon on June 21, 2009, 11:42:18 PM
Can you post an example of code that reproduce the problem please.
Title: Re: Console Applications
Post by: Paolo_R on June 21, 2009, 11:49:59 PM
Nicolas: I have attached testcurs.c from the demo programs.

Compiles and builds OK but just hangs when run in an XP console.
Title: Re: Console Applications
Post by: nicolas.sitbon on June 22, 2009, 12:11:41 AM
OK, i just understand what you say, it is the normal behaviour. You have 2 possiblities :
- put pdcurses.dll in system32
- add C:\Program Files\PellesC\Bin to the %PATH% environment variable
Title: Re: Console Applications
Post by: Seltsamuel on June 22, 2009, 10:19:28 AM
Hi,

third option:
put the .dll beside the executable inside your project folder.

I personally prefere this because of dllhell and different versions of dlls ;-)

Greetings

Seltsamuel
Title: Re: Console Applications
Post by: nicolas.sitbon on June 22, 2009, 10:36:43 AM
Hi,

third option:
put the .dll beside the executable inside your project folder.

I personally prefere this because of dllhell and different versions of dlls ;-)

Greetings

Seltsamuel
you need an update : http://www.davidlenihan.com/2007/07/winsxs.html (http://www.davidlenihan.com/2007/07/winsxs.html)
Title: Re: Console Applications
Post by: Paolo_R on June 22, 2009, 10:51:46 AM
Well,  I've spent the day compiling sample programs found in the Index of /HOWTO/NCURSES-Programming-HOWTO.

Some compile and run fine, some I needed to correct for them to run, and others either hang, or bomb due to access violations.

However, I have discovered that the Menu and Form functionality is not implemented in PDCurses - apart from the basic curses functionality only the Panels functions are implemented. This rather limits the use of PDCurses as a windowing/menu based/form data entry library. A bit disappointing really.
Title: Re: Console Applications
Post by: nicolas.sitbon on June 22, 2009, 10:58:37 AM
Here are all the functions defined by the standard : http://opengroup.org/onlinepubs/007908799/xcurses/curses.h.html (http://opengroup.org/onlinepubs/007908799/xcurses/curses.h.html)
Please can you tell me which functions aren't implemented?
thanks.
Title: Re: Console Applications
Post by: Paolo_R on June 22, 2009, 11:25:18 AM
Nicolas: PDCurses provides curses.h and panel.h functions but the menu.h and form.h are not provided.

I tried compiling a menu demo program starting thus:

#pragma comment(lib, "pdcurses.lib")
#include <curses.h>
#include <menu.h> ....

and got this error:

C:\WORKAREA\pdcurses tests\menu1\menu1.c(3): fatal error #1035: Can't find include file <menu.h>.

I researched this and found some conversations involving W McBrine (who I believe is supporting PDCurses) and they implied menus and forms are not available.
Title: Re: Console Applications
Post by: nicolas.sitbon on June 22, 2009, 11:45:19 AM
menu.h is an extension, it is not part of opengroup standard.
Title: Re: Console Applications
Post by: Paolo_R on June 22, 2009, 11:56:13 AM
OK, it may not be part of opengroup standard but it certainly seems to be part of ncurses. I believed that pdcurses was an implementation of ncurses.
Title: Re: Console Applications
Post by: nicolas.sitbon on June 22, 2009, 12:16:54 PM
Quote
PDCurses is a public domain curses library for DOS, OS/2, Win32, X11 and SDL, implementing most of the functions available in X/Open and System V R4 curses
Title: Re: Console Applications
Post by: Paolo_R on June 22, 2009, 12:33:44 PM
Nicolas: I obviously misunderstood. thanks for your assistance.
Title: Re: Console Applications
Post by: nicolas.sitbon on June 22, 2009, 12:36:51 PM
You're welcome.  :)
Title: Re: Console Applications
Post by: Romashka on June 22, 2009, 01:06:18 PM
One comment, I have tried building some of the demo programs that came with the GnuWin version. Some wouldn't run 'cos they couldn't 'find' pdcurses.dll, so I put a copy in my windows/system32 folder and that solved that problem. Why do I need to do this if Pelles C compiler already has a copy in its /bin folder?
pdcurses.dll must be either in the same directory as exe file you're running or in c:\windows\system32 directory
Title: Re: Console Applications
Post by: jwzumwalt on June 28, 2009, 06:46:16 PM
Would you please post a link to a zip file with the working examples? Or you can e-mail them to me and I will make them avalable on my site....

jwzumwalt(at)rock(dot)com
Title: Re: Console Applications
Post by: Paolo_R on June 28, 2009, 09:33:04 PM
I cut'n'pasted the source code from http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ncurses_programs/
Title: Re: Console Applications
Post by: jwzumwalt on June 29, 2009, 09:01:20 AM
Got em', thanks!