Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: tazor on 25 March 2003, 05:43

Title: C Programing in Linux
Post by: tazor on 25 March 2003, 05:43
I learnt C using a Borland compiler. I now use Red Hat but I've found that the compiler built in with Linux uses different header files and I need to re-write a lot of my stuff just to get it to compile.

I have heard there is a compiler for Linux that uses the same header files as Borland, and is basically Borland for Linux.

Does anyone know where I can find this and what it is called? Does anyone have any better suggestions?

I would just learn the Linux header files, but I'm still learning the Borland ones, and learning them is not optional (Student demands).
Title: C Programing in Linux
Post by: slave on 25 March 2003, 06:16
Do you use conio.h or something?  Linux uses ncurses which is kind of similar.  I'd suggest just getting used to programming with gcc, everyone uses it.  Borland costs money I think anyway.  And what C class makes you use Borland?  Even  mine (which is dumb as dirt so far) uses gcc on solaris machines.
Title: C Programing in Linux
Post by: Kintaro on 25 March 2003, 08:59
Gee TaZoR where abouts in aussie do you live? I live in 9 Coram Close Narre Warren, Victoria.

You?
Title: C Programing in Linux
Post by: Kintaro on 25 March 2003, 21:03
(TaZoR is my brother)

We found out if we just ditch the conio it works, and that getch is getchar. A few other things, he runs Red-Hat 8.0, and uses GNOME.
Title: C Programing in Linux
Post by: slave on 25 March 2003, 21:09
What's the program you're writing?  Can I have a look?
Title: C Programing in Linux
Post by: Kintaro on 25 March 2003, 10:25
Uhm, ask him.
Title: C Programing in Linux
Post by: SAJChurchey on 25 March 2003, 11:00
Kylix 3 Open Edition is from Borland, and it's a free download w/ a built in C/C++ environment.  It should be backwards compatible w/ their headers hopefully.
Title: C Programing in Linux
Post by: tazor on 26 March 2003, 04:49
Sounds good.

The programming book I have and all the things at TAFE are for learning Microsoft/Borland style C. I figured that it would be a bit too much to learn both sets of headers at once.

I do plan on learning gcc, but I'll wait until after the exams.

Just for the record, I was using the conio.h header and I also couldn't find an equivalent of clrscr().

Call me an idiot, but then I am related to Food.  ;)
Title: C Programing in Linux
Post by: slave on 26 March 2003, 07:14
quote:
Just for the record, I was using the conio.h header and I also couldn't find an equivalent of clrscr()


Use the command

clear();

Make sure you #include <ncurses.h> and compile your program with the -lncurses option, like this:

gcc hello.c -lncurses


Oh, and make sure to issue a refresh() to redraw the screen afterwards.

Hope that helps.
Title: C Programing in Linux
Post by: tazor on 28 March 2003, 04:20
Yeah, thanks.

Perhaps I should just send out my source code and then I'll see what changes have to be made.

I did have a problem that one of the programs I made. I converted what I new from borland style to linux style. But when I went to compile it (it didn't show any errors) the compiled program was nowhere to be seen, although it seemed to compile alright.
Title: C Programing in Linux
Post by: tazor on 29 March 2003, 18:06
Well, I'm not out of trouble yet.

I've converted a program to gcc, but I'm having touble with the math.h library, I think. This is what is happening when I try to compile:  
quote:
[tazor@tazor dev]$ gcc EngOCalc.c -o EngOCalc -lncurses
EngOCalc.c: In function `main':
EngOCalc.c:14: warning: return type of `main' is not `int'
/tmp/ccWMnoWD.o: In function `main':
/tmp/ccWMnoWD.o(.text+0x2cf): undefined reference to `sqrt'
/tmp/ccWMnoWD.o(.text+0x2de): undefined reference to `sqrt'
/tmp/ccWMnoWD.o(.text+0x2ed): undefined reference to `sqrt'
/tmp/ccWMnoWD.o(.text+0x341): undefined reference to `sqrt'
/tmp/ccWMnoWD.o(.text+0x350): undefined reference to `sqrt'
collect2: ld returned 1 exit status

Title: C Programing in Linux
Post by: flap on 29 March 2003, 18:28
You need to link with the math library as well.

gcc EngOCalc.c -o EngOCalc -lncurses -lm