 |
 |
Mac OS X cc vs. FreeBSD gcc?
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
I'm taking a course on C (no C++, no Obj-C, just C) and either I have to buy a dirt-cheap machine and put FreeBSD or OpenBSD on it with the standard gcc compiler, or I can use my Mac OS X box and use Apple's cc.
Now, I need to know that cc can compile C (this is a advanced C for Unix class -- that's what it's called) NO hassles whatsoever. This will be using some Unix libraries. Does OS X meddle with those in any way?
Basically I need a standard compiler running a Unix that can do standard stuff. It's alright if cc does stuff normally, but I just need to make 100% sure that either cc hello.c or cc -traditional-cpp hello.c will work flawless and identically to Linux or FreeBSD/OpenBSD.
Much appreciated. I really hope OS X can pull this off (I know Gametes has some issues with cc with his C++ code, but I just need this for C -- I assume it'll be standard printf() fopen() stuff like that).
Thanks a bunch. I need this for something else, hopefully I can move to Obj-C/Cocoa in a few months. =)
thanks again
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Most things should work OK. But if you want stability, don't use a beta OS :-)
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
This isn't happening right now -- it'll be a few months after Final Release. But what does "most" things mean?
Either it works properly or it doesn't...
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
You'll be able to use all the UNIX functions you want, such as BSD sockets, threads, &c. in a standard way.
I'll try writing something with curses and see how that works, but I haven't had any problems with C so far. The C++ problem Gametes was having dealt with a minor (not crippling) bug in the iostream library.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
and...?
any problems?
It's looking good so far!
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: Tokyo, Japan
Status:
Offline
|
|
As far as pure c goes, there'd be little, if any, difference between OS X cc and the rest of *nix gcc when -c option, which compiles object code without invoking subsequent ld, is given. However, when you link object files to produce executables, you might encounter some oddity. Famous one is a math library, i.e. libm. Under OS X, there's no libm although it provides all libm's functionality. If source code includes <math.h>, we usually do (g)cc -o myapp myapp.c -lm; under OS X, we do cc -o myapp myapp.c, instead. This is because Apple's library organization is a little, well maybe a lot, different from the other BSDs at least for now.
They appear to be reorganizing libraries that originate from BSDs back in the traditional location such as /lib and /usr/lib. So things may change after the final or versions after that.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
You completely lost me. Could you say that again in English?
I asked Stan Shebs and he said that everything should work fine. He said cc was gcc, and that the GM especially will fix things since it'll fix up some Unix-y quirks people noticed in the Beta. It'll apparently come with a load of BSD libraries too.
so what's going on? (I asked him at the Omni dev list yesterday)
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: Tokyo, Japan
Status:
Offline
|
|
Originally posted by gorgonzola:
You completely lost me. Could you say that again in English?
I'm sorry, gorgonzola, if my English confused you. Stan Shebs's words are authoritative since he's the one maintaining the compiler.
Well, what I was trying to say is this. Could be long so bear with me.
We need to take a few steps in order to make a program. First, we write (type) code in text form, a human readable format, and save it somewhere. This process is called coding. Next, we turn the text file(s) into the machine code. This chunk of code is saved in a file called object file (please note that this object is nothing to do with object oriented programming). Compiling is the term for this process. Although the object file consists of machine code, it cannot run until it is combined with a run time library that does the job interfacing your object code and the operating system and with other precompiled objects if any (see below). The last process is called linking. In short, we need to go through three steps, coding, compiling, and linking, in order to create a program that can do something. cc or gcc lets you do the last two steps in a single command, but it also allows you to do just compiling. The '-c option' thing in the last my post does just that.
You may notice that there would be many things everybody would do in the same manner. These things, constants, definitions, and methods (functions in C), are usually supplied by operating systems. Otherwise we have to reinvent the wheel every time we need them. They put functions together according to their similarity and provide libraries that are archives of object code. You may have heard of header files. These files are in human readable text format and give information to human beings as to how to use functions among other things. In addition, header files inform a compiler that you are about to use one or more constants or functions in the library. If you need to use one of math functions, for example sine, you usually want to use a ready made sin() function. This function is declared in the "math.h" header file. So, you put a line in your code file like this:
#include <math.h>
When you compile your code with the -c option, a compiler creates an object file. In the object file, however, there is no actual code for the sine function but a stub that just promises that the sine function is somewhere outside of your code. That's ok because you eventually link libraries in order for the program to be useful. Up until now, cc (that's gcc from Apple) and gcc from other BSDs do exactly the same thing. In other words, if your code is compiled on your mac running OS X, it will be also compiled on a machine in your class running FreeBSD without a problem.
You then link the object file just created against the runtime library and other libraries if necessary. Since every object file must be linked with the runtime library, cc/gcc automatically links the library by default so that you don't have to instruct the compiler to link it on any platforms. Math functions, however, have been traditionally stored in the math library called libm and you have had to explicitly link the library at the link time. In order to do this, you put an option switch -lm at the end of command line. This is still true on the *other* BSDs. Now fun part begins. Apple, for some unknown reason, decided to break this convention and put the entire math functions somewhere (I don't know where), and made the compiler automatically link the library at link time. It has become a ususal suspect ever since when you have trouble compiling/linking some code from other platforms on OS X, because the rest of the unix world assumes that the math library needs to be linked with the -lm option. This is the oddity I was talking about in the last post.
This may be a public beta specific issue and there might be no oddity like this after the final. I'm just crossing my fingers for that.
Well, I hope I was a little bit clearer than last time. Enjoy your class, gorgonzola. I'd go to ESL class in summer
ps
Hmm... this brings me a question that when Apple will release dev tools for the final. I've read someone writing the tools for PB won't work under the final. We just have to wait for a few weeks probably...
[This message has been edited by tea4u (edited 03-02-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
Thank you. It wasn't your english I couldn't get, it was the density of coding jargon.  I'm not quite that comfortable with *nix yet.
What you mention about libm is interesting.
So what on FreeBSD would be:
%> cc hello.c -lm
on Mac OS X would be:
%> cc hello.c
Is this right? I assume the cc could also be:
%> cc -c hello.c
or
%> cc -traditional-cpp hello.c
but this shouldn't affect the -lm thing should it.
I'll ask stan shebs again just to double check.
thanks again
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
Here we go (Stan Shebs' response -- quotes bits are from my post quoting parts of tea4u's post):
> and put the entire math functions somewhere
> (I don't know where), and made the compiler automatically link the library
> at link time.
They're all in the System framework (/usr/lib/libSystem.dylib).
> It has become a usual suspect ever since when you have trouble
> compiling/linking some code from other platforms on OS X, because the rest
> of the unix world assumes that the math library needs to be linked with the
> -lm option.
In 1.0, -lm will work just as it does for everybody else; that was one of
the compat changes I was referring to earlier. All we do is symlink libm.dylib
to the System framework, so the -lm is never actually required, but if your
makefile or script has a literal -lm wired into it, it won't complain.
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2000
Location: Toronto, ON
Status:
Offline
|
|
Gorgonzola:
I'm certainly no *nix expert, but couldn't you install the PPC OpenBSD on your current Mac?
http://www.openbsd.org/2.8_packages/powerpc.html
Reggie
(edit: changed Free to Open, doh!)
------------------
"A flute without holes, is not a flute. A donut without a hole, is a danish."
- Ty Webb, "Caddyshack"
[This message has been edited by ReggieX (edited 03-10-2001).]
|
|
The Lord said 'Peter, I can see your house from here.'
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Nov 2000
Location: New Yawk
Status:
Offline
|
|
That would certainly be an option and would save the money on another box. But obviously I'd rather use OS X than even OpenBSD on my Mac (especially since I have a 6GB drive and can't take partitioning very well -- you get such tiny partitions!).
thanks though, I completely overlooked that!
*slaps head*
------------------
the oddball newsletter
------------------
it's only after you lose everything that you're free to do anything
|
|
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|