PDA

View Full Version : Beginner Compiler




Melkor
Feb 10, 2006, 04:51 PM
So I just started doing a bit of c programming in college and am having a bit of trouble.

I want to be able to do my homework assignments on my powerbook, but I can't seem to figure out how xcode works.

So I'm looking for a more basic compiler where I can just type in my code and click build. (Like a mac version for the Dev compiler)

All we're doing is building very basic programms, like pinting out the Fibonacci series and converting farenheit to celcius, so I just need something very simple.

Thanks a lot :)



Mitthrawnuruodo
Feb 10, 2006, 05:05 PM
The best would probably be to download a nice, free text editor, like TextWrangler (http://www.barebones.com/products/textwrangler/). Write your code in that and compile and run via Terminal...

Make a file with the code, name it file.c. Open Terminal use cd to get to the directory (folder) where the file is.
Compile with gcc -o program file.c
And run it with ./program

Of course you can use other names for your file and executable... ;)

zimv20
Feb 10, 2006, 05:38 PM
damn, i thought from the thread title that the OP was going to write his own compiler. i was hoping we'd be talking about token generators and such.

Melkor
Feb 10, 2006, 07:36 PM
The best would probably be to download a nice, free text editor, like TextWrangler (http://www.barebones.com/products/textwrangler/). Write your code in that and compile and run via Terminal...

Make a file with the code, name it file.c. Open Terminal use cd to get to the directory (folder) where the file is.
Compile with gcc -o program file.c
And run it with ./program

Of course you can use other names for your file and executable... ;)


That's just what I wanted. Thanks a lot man.

iSee
Feb 10, 2006, 08:41 PM
Also, using gcc directly like that is a great way to learn. You'll use it for a while and then when you're ready to switch to Xcode, you'll understand what it's doing under the hood--exactly what you've been doing by hand.

GilGrissom
Feb 26, 2006, 09:04 AM
Hey guys.

Sorry to sound stupid here, but I'm in pretty much the exact same position as the OP.

I tried that gcc command in the terminal, but it says "command not found". What stupid thing am I doing wrong here?

Any help would be appreciated!

Mitthrawnuruodo
Feb 26, 2006, 09:07 AM
I tried that gcc command in the terminal, but it says "command not found". What stupid thing am I doing wrong here?Have you installed Developer Tools?

GilGrissom
Feb 26, 2006, 09:16 AM
Have you installed Developer Tools?
From the XCode folder?

Mitthrawnuruodo
Feb 26, 2006, 09:41 AM
From the XCode folder?Yes...? Is it called that, and not Developer Tools?

GilGrissom
Feb 26, 2006, 09:50 AM
Yes...? Is it called that, and not Developer Tools?Theres a Developer Tools package inside the XCode folder in Applications.


UPDATE:

I've installed the "DeveloperTools.pkg" file under "Installers>XCode Tools>Packages"...still nothing, still get "Command not found" when I try and run gcc under terminal.

Mitthrawnuruodo
Feb 26, 2006, 10:12 AM
Did you restart (or at least log out and back in) after installing Developer Tools?

GilGrissom
Feb 27, 2006, 01:49 PM
Did you restart (or at least log out and back in) after installing Developer Tools?
Ye...total reboot, still no luck!

Theres gotta be something really stupid and silly that I simply haven't done or something!

Thanks for your help.

Any ideas?

balamw
Feb 27, 2006, 01:52 PM
Ye...total reboot, still no luck!

Theres gotta be something really stupid and silly that I simply haven't done or something!

Thanks for your help.

Any ideas?
It sounds like somehow your Terminal path environment variable doesn't include the path where gcc lives.

type set (or setenv) and see what PATH is.

B

GilGrissom
Feb 27, 2006, 01:57 PM
It sounds like somehow your Terminal path environment variable doesn't include the path where gcc lives.

type set (or setenv) and see what PATH is.

B
"set" has revealled:

PATH=/bin:/sbin:/usr/bin:/usr/sbin

gekko513
Feb 27, 2006, 02:02 PM
Theres a Developer Tools package inside the XCode folder in Applications.


UPDATE:

I've installed the "DeveloperTools.pkg" file under "Installers>XCode Tools>Packages"...still nothing, still get "Command not found" when I try and run gcc under terminal.
Is that the main Xcode installer? If it isn't and you haven't installed Xcode, you could try to install the whole thing.

GilGrissom
Feb 27, 2006, 02:09 PM
Is that the main Xcode installer? If it isn't and you haven't installed Xcode, you could try to install the whole thing.
I have no idea! This is my first experience with XCode on any level!

I've found an XCode Tools.pkg installer just inside the XCode Installer folder, see if this herralds some promising results!

yellow
Feb 27, 2006, 02:13 PM
gcc should be in /usr/bin/, so since it's in your path, it's probably not installed ("which gcc" will tell you). You should get the latest version of XCode tools from the Apple developer website (http://developer.apple.com). It's free to sign up, and it's free to download. But it's VERY larger. 800+MB I believe, so prepare for that.

xcode_2.2.1.dmg

Once you have the DMG downloaded, you double click the XcodeTools.mpkg to install it.

grabberslasher
Feb 27, 2006, 02:25 PM
Just install the full Xcode tools and restart. Gcc should work fine then.

GilGrissom
Feb 27, 2006, 02:28 PM
That XCode Tools.pkg I just found has now given me gcc. Thanks guys!

How out of date will my XCode be and will it affect compiling basic C at all?

(Im supposed to get it to compile on a Unix box at uni, but cannot access it from home, so Im compiling it on my PowerBook and then I'll do any minor debugging when I'm on site at uni when I have access to the Unix box.)

Is it worth me getting the very latest XCode or just sticking with what I already have? (OS X 10.4.5)

Thanks guys for your help!

gekko513
Feb 27, 2006, 02:32 PM
For just using gcc for a uni course I don't think it would make any difference.

yellow
Feb 27, 2006, 02:33 PM
wasn't there a bug in earlier version of gcc4? AH, it was gcc3. From the Dev site:

The November 2004 gcc 3.3 updater provides improvements to C++ compatibility and debugging of code build using dead code stripping. This updater can only be applied to Xcode Tools 1.5. The August 2003 gcc updater GCC updater includes the GCC 3.3 compiler in addition to other updates that will allow development of G5 optimized code using the December 2002 release of the Mac OS X Developer Tools.

Don't know if this is effect you or not.

I just want to make sure GG doesn't get screwed somewhere along the way trying to find a bug that isn't in his code.

GilGrissom
Feb 27, 2006, 02:50 PM
Any debugging I do is only to make sure that my Mac compiler hasn't used any special items that are different to what the Unix compiler on the uni server would use (e.g.: we've been told to avoid using Windows as it will compile slightly differently and add things that the Unix box cannot compile.) We can write and compile the code on whatever we want but have to demo the code compiling and running on the Unix box come the hand-in date. (confused?...I sure am!)

Sorry if this is slightly off topic now, but do you happen to know how different, if there is any difference, the Mac OS X gcc compiler is to the compiler that this Unix box will have? Don't worry if you don't know, I'm just curious. Sorry I don't have any Unix version numbers or anything, it's just a Compaq box with Unix on it! Am I right in saying there shouldn't be much difference at all, being as OS X is based on Unix?

I know it shouldn't matter anyway as I doubt I'll be using any special things that are unique to certain compilers anyway, so it should run fine regardless.

But anyway, thanks for all your help guys! You've all been invaluable!!

(Yey I can now compile C on my Mac!...gutted I have to do C in the first place! lol!)

gekko513
Feb 27, 2006, 03:00 PM
For strict ANSI-C it should be identical, but if you start doing things with system(...) or include platform specific C-libraries like glibc or similar, there can be differences.

yellow
Feb 27, 2006, 03:22 PM
What gekko said. For all intents and purposes the gcc on the Mac will be the same on another flavor of UNIX. Different libraries may apply, and as gekko said, hardware specific code will certainly be different. But all in all, it's just a GNU C Compiler.

mstriker
Oct 13, 2011, 06:09 PM
Originally Posted by Mitthrawnuruodo
The best would probably be to download a nice, free text editor, like TextWrangler. Write your code in that and compile and run via Terminal...

Make a file with the code, name it file.c. Open Terminal use cd to get to the directory (folder) where the file is.
Compile with gcc -o program file.c
And run it with ./program

Of course you can use other names for your file and executable…


Just wanted to thank you for your answer. Indeed it worked. I am self-studying C and wanted a compiler for my iMac to run programs. Had no idea where to begin.
1. Installed xCode ver 3.2.3. from the app-CD that came with the iMac. Tested gcc in the terminal line - the command was recognized.
2. Downloaded TextWrangler from BareBones website and installed.
3. Created a hello.c simple file and saved it on the Desktop
4. Changed directory by typing in the terminal window cd Desktop. Made sure the file was there by typing ls, it was.
5. Compiled the file and run the executable.

Thanks man for the guidance. I can practise now!!!!

GorillaPaws
Oct 13, 2011, 08:18 PM
Just wanted to thank you for your answer. Indeed it worked. I am self-studying C and wanted a compiler for my iMac to run programs. Had no idea where to begin.
1. Installed xCode ver 3.2.3. from the app-CD that came with the iMac. Tested gcc in the terminal line - the command was recognized.
2. Downloaded TextWrangler from BareBones website and installed.
3. Created a hello.c simple file and saved it on the Desktop
4. Changed directory by typing in the terminal window cd Desktop. Made sure the file was there by typing ls, it was.
5. Compiled the file and run the executable.

Thanks man for the guidance. I can practise now!!!!

The Masters of the Void tutorial (http://masters-of-the-void.com/) is an excellent guide for learning C on the Mac and it will introduce you to the basics of Xcode. When you decide you want to learn how to use Xcode that might be a good resource for you.

balamw
Oct 15, 2011, 05:10 PM
Wow. A blast from the past.

Just a quick note: You can get compilers without Xcode here:

https://github.com/kennethreitz/osx-gcc-installer

or

http://hpc.sourceforge.net/

B