Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cocopelli

macrumors member
Original poster
Sep 5, 2002
58
0
Spokane, Wa.
Hi um im new to mac rumors but I was just wondering if anyone knows of a free C compiler for mac that is compatible with turbo C for windows. I have a comuter science class where we are learning to program in C but the compiler(Turbo C) the teacher wants us to use is only available for windows and she did not give us an alternative that would run on a mac. I did search downloads.com but didnt find anything any help would be greatly appreciated thanx so much
 
this will make me sound really dumb but where do I find it at? i downloaded developer tools but didnt see it am i just missing it or wot? is it called GCC? thanx again for your help
 
As long as you're not doing anything with graphics in Turbo C, just about anything else will be a good substitute.

If you need to capture output, running your programmes on Mac OS X will be quite a bit more convenient than using a DOS shell in Windows.

Remember that in DOS/Windows, you can run the executable programme directly by typing its name without the .EXE extension but in Mac OS X precede the name with ./ (period slash). If you're running from Project Builder, you may find it inconvenient to run programmes that make use of standard output and will want to run them directly at the shell prompt.
 
gcc

The GCC compiler comes with OS X. You just need to install the developer tools. Doing complex things with it from the command line (Terminal.app) can be hard, so fortunately, the Developer Tools also come with Project Builder, which is a nice IDE for C, C++, Objective-C, Java, and maybe a few others.

You could also try the relatively expensive CodeWarrior. For some reason.

I recommend using Project Builder. It's free, it's from Apple, it compiles via GCC, and Mac OS X comes with standard C libraries, which seems to be what you need.
 
This is not a question totally related to the C compiler, but it's similar. Does OS X or Project Builder have something we can compile Perl on? I read on the Perl.com page that if you have a C compiler, you can compile Perl.

Also, if I want to compile C, do I just go to Project Builder and click on new file? I selected the option that said something like "C Compiler (Carbon)". Is this the one you guys were talking about? I didn't see an option for Perl, which is why I'm asking.

Thanks.
 
Still Lost??????

Thanx everyone for your help I found the program and got it installed. But I have been having trouble getting it to work. Everything loads fine but when I type the code and try to build it gives an error and says build failed. This is the first time I have ever done any programming of any kind so it is probably user error but i dont know where it is. I had my instructor look at it but she had never used GCC so she didnt know how to fix it. Heres how I had it set up: Launch Project Builder; new project select carbon app; new file select c file under the carbon list; type the following

#include <stdio.h>

main ()

{
printf ("Hello");
}
I know this is very basic stuff but is there a problem with my formatt is it different for GCC than it is for Turbo C?

this exact same code on my friends PC running turbo C returns "Hello"

my compiler says error main type does not return int
reaches end of non void function
Build Failed

I am completely lost I dont know what to do I have an assignment due on Wednesday morning and if I cant figure it out I will have to(Shudder) use the schools PCs until I get VPC please help
 
dude....

usually we start the main program as

#include <iostream.h>
#include <other library needed>

int main()
{
cout << "hello world!" << endl;
return 0;
}

i have never used stdio.h, though... just a lowly AP CS II student on a PC, trying to get a mac... i hope it's not too troublesome when i finally do.

i have never seen a function without a return type, even if it's just void, and you can always use void instead of int if you want, but it's bad for debugging, i am told. yeah, type void before main!
 
ANSI C...

Sometimes requires main() to return an int so...

#include <Carbon/Carbon.h>

int main ()

{
printf ("Hello");

return 0;
}

but maybe not (haven't done this stuff for a little while)... compiling in OSX with project builder takes a couple hours to become familiar with (such as linking Carbon/Carbon.h instead of stdio.h etc...), so don't give up so soon... you won't regret it :)
 
Here's what you should do:

The GCC everybody talks about is actually NOT project builder... It's a command within Terminal.

I'm going to set up some steps for ya:

1.- Find and Run Terminal (it's in a directory called Utilities, within Applications, in your hard drive)
2.- Type your program in a text file format. (You can use either emacs or pico, but since you say you are new to this endeavors, I would recommend using BareBones Edit lite, which you can get at www.barebones.com. You can also use TextEdit, included in you copy of MacOSX, in the folder Aplications). Anyway, when you type the program, save it in you Home folder (the one whose icon is a house) with a filename ending in .c (for example, hello.c).
3.- The program should read:

#include <stdio.h>
int main(void)

{
printf("Hello");
return 0;
}

And that's it.

4.- After you saved your program, go to terminal and type:

cc hello.c

The program will compile, and then you can run it using.

./a.out

a.out is the name of your compiled program, and it's an executable Unix file.

I think I didn't forget anything, but if you have any other questions, post again and I'll try to help you.
 
Shadowfax... that's C++, he's using C. :)

According to the ANSI standard for C, main() must return an int. A return value of "0" is means the program executed correctly.
 
lol, i guess i am not that old school... in my defense, i got the principle of return value, lol... and a 4 out of 5 possible on the AP exam... but yeah, i haven't used stdio at all, so.. sorry to lead the man astray.
 
You can still use Project Builder if you want to compile plain C applications. I don't recommend making it a Carbon project in PB, because that sets the target of the project to something you don't want.

What you can do is scroll all the way to the bottom of the project selection list and choose "Standard Tool". That will let you program in plain C.

As for perl in OSX, it's already there if you've installed the Dev Tools (maybe if you haven't, not sure). It'll already work with the Personal Web Sharing/Apache if you want to use it on the net, or the Terminal is just great. You may find something useful by typing 'man perl' (no quotes) in the Terminal window, but that may be too hard to sift through.

Good luck!

(BTW, I love OSX because anything that my college CS classes have us doing, I can do just great on my clamshell... Hooray for UNIX!)
 
Project Builder...

Originally posted by jrbohorquezg
Here's what you should do:

The GCC everybody talks about is actually NOT project builder... It's a command within Terminal.

I'm going to set up some steps for ya:

1.- Find and Run Terminal (it's in a directory called Utilities, within Applications, in your hard drive)
2.- Type your program in a text file format. (You can use either emacs or pico, but since you say you are new to this endeavors, I would recommend using BareBones Edit lite, which you can get at www.barebones.com. You can also use TextEdit, included in you copy of MacOSX, in the folder Aplications). Anyway, when you type the program, save it in you Home folder (the one whose icon is a house) with a filename ending in .c (for example, hello.c).
3.- The program should read:

#include <stdio.h>
int main(void)

{
printf("Hello");
return 0;
}

And that's it.

4.- After you saved your program, go to terminal and type:

cc hello.c

The program will compile, and then you can run it using.

./a.out

a.out is the name of your compiled program, and it's an executable Unix file.

I think I didn't forget anything, but if you have any other questions, post again and I'll try to help you.
...is a front end for GCC.

As stated above, to fix the program, add "int" in front of main, and add "return 0;" just before the closing brace.
 
Originally posted by kperry8
You can still use Project Builder if you want to compile plain C applications. I don't recommend making it a Carbon project in PB, because that sets the target of the project to something you don't want.

just to clarify (for cocopelli), there's nothing wrong with building a Carbon app in either C or C++... if this is for a general C class you can still link to stdio.h, math.h, stdarg.h, etc instead of the Carbon framework and the code will compile on Windows too (simple programs).
 
Ok I might be wrong as my C is a little rusty as I mainly code in C# these days. Some where in my rusty brain says that main can return different integers depending on the state of the program when it exits. e.g. exited correctly. I'd try placing a int before the main declation to explictly tell the prog that a value is returned. Oh yeah I've just noticed about 10 other posts all saying the same thing, damn my lousy eyes.


Gaz
 
Actually, if you're programming for Windows...

... returning different integers won't work. To set the ERRORLEVEL value, you must do an explicit exit() call. This works in Unix too, but to my way of thinking it should be unnecessary.

e.g. if you get an error: exit( 1 );
 
thank u every 1 4 ur help. i got it to compile in project builder and in terminal but i do have a couple more questions. the first is in project builder, under the run log it says "Hello World c program(the name of my program) has exited with status 0" and at the bottom of the screen it says "c program exited normally". i am assuming that all this is good and how its supposed to be because it has not given me any errors. my question is how do i see the output after i run the program? in Turbo C u type alt F5 and the little black screen comes up, does project builder have a feature like this? were do i find it? next question ok im supposed to turn in my program but the teacher does not want the executable she wants the code file how do i know wich file i am sending ? last ? if I decide to do the compiling using terminal how do i find the right file to send in? and will this file run in windows or only unix? thanx again for your help
 
Originally posted by cocopelli
thank u every 1 4 ur help. i got it to compile in project builder and in terminal but i do have a couple more questions. the first is in project builder, under the run log it says "Hello World c program(the name of my program) has exited with status 0" and at the bottom of the screen it says "c program exited normally". i am assuming that all this is good and how its supposed to be because it has not given me any errors. my question is how do i see the output after i run the program? in Turbo C u type alt F5 and the little black screen comes up, does project builder have a feature like this? were do i find it? next question ok im supposed to turn in my program but the teacher does not want the executable she wants the code file how do i know wich file i am sending ? last ? if I decide to do the compiling using terminal how do i find the right file to send in? and will this file run in windows or only unix? thanx again for your help

if you followed the steps that i outlined before, the file that you should turn in is the one which name has a .c extension. In general, just paste the code on a text editor and name it with a file_name.c
 
Originally posted by cocopelli
thank u every 1 4 ur help. i got it to compile in project builder and in terminal but i do have a couple more questions. the first is in project builder, under the run log it says "Hello World c program(the name of my program) has exited with status 0" and at the bottom of the screen it says "c program exited normally".

you should see "hello" in that same window panel before it says "Hello World c program has exited with status 0". status 0 is what you get with the "return 0;".


next question ok im supposed to turn in my program but the teacher does not want the executable she wants the code file how do i know wich file i am sending ? last ? if I decide to do the compiling using terminal how do i find the right file to send in? and will this file run in windows or only unix? thanx again for your help

you'd turn in the file "Hello World.c"... this file wll compile under windows of course. i wouldn't bother compiling it in the terminal because you're doing the exact same thing in project builder (both use gcc). the "Hello World.c" file will be in the project folder you created in project builder.
 
gotta watch those sneaky file names eh? well it's just a first time thing. you'll get the hang of it really quick. good luck.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.