Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C compiler

1 view
Skip to first unread message

san...@gmail.com

unread,
Mar 29, 2007, 10:25:56 PM3/29/07
to
I just got my first mac (a macbook), after using Linux for many
years. Seems like it takes a lot of effort to get up an environment
that can build things, such as open source packages. I've downloaded
Xcode and installed some packages that looked like they made sense,
including gcc, developer tools, and extras. I am trying to compile a
simple C program, with no luck.

$ cat try.c
#include <stdio.h>

int main() {
printf("hello world\n");
return 0;
}

$ gcc try.c
try.c:1:19: error: stdio.h: No such file or directory
try.c: In function 'main':
try.c:4: warning: incompatible implicit declaration of built-in
function 'printf'

$ gcc -I /Developer/SDKs/MacOSX10.4u.sdk/usr/include/ try.c
/usr/bin/ld: can't locate file for: -lcrt1.o
collect2: ld returned 1 exit status

Help.. what's next?

Thank you,
- Ben

Dave Seaman

unread,
Mar 29, 2007, 10:50:34 PM3/29/07
to
On 29 Mar 2007 19:25:56 -0700, san...@gmail.com wrote:
> I just got my first mac (a macbook), after using Linux for many
> years. Seems like it takes a lot of effort to get up an environment
> that can build things, such as open source packages. I've downloaded
> Xcode and installed some packages that looked like they made sense,
> including gcc, developer tools, and extras. I am trying to compile a
> simple C program, with no luck.

You say you installed gcc and *also* the developer tools? Perhaps that's
your problem. The developer tools already include a working gcc. If you
attempted to install a different gcc and didn't get it right, perhaps
that explains the problem you are having.

> $ cat try.c
> #include <stdio.h>

> int main() {
> printf("hello world\n");
> return 0;
> }

> $ gcc try.c
> try.c:1:19: error: stdio.h: No such file or directory

Try "ls /usr/include/stdio.h". There are two possibilities. If the file
does not exist, then you didn't install the developer tools. If the file
exists but gcc can't find it, then you are not using /usr/bin/gcc, which
is the version installed with the developer tools, but some other gcc
instead. Where did you get this other gcc?

> try.c: In function 'main':
> try.c:4: warning: incompatible implicit declaration of built-in
> function 'printf'

Try "which gcc". You should get /usr/bin/gcc. If you get something
else, then repeat the experiment, using "/usr/bin/gcc try.c" in place of
the above.

> $ gcc -I /Developer/SDKs/MacOSX10.4u.sdk/usr/include/ try.c
> /usr/bin/ld: can't locate file for: -lcrt1.o
> collect2: ld returned 1 exit status

> Help.. what's next?

Apple's gcc works. You must have done something to mess it up.

--
Dave Seaman
Oral Arguments in Mumia Abu-Jamal Case to be heard May 17
U.S. Court of Appeals, Third Circuit
<http://mumia2000.org/>

san...@gmail.com

unread,
Mar 29, 2007, 11:11:30 PM3/29/07
to
On Mar 29, 10:50 pm, Dave Seaman <dsea...@no.such.host> wrote:

> On 29 Mar 2007 19:25:56 -0700, sand...@gmail.com wrote:
>
> > I just got my first mac (a macbook), after using Linux for many
> > years. Seems like it takes a lot of effort to get up an environment
> > that can build things, such as open source packages. I've downloaded
> > Xcode and installed some packages that looked like they made sense,
> > including gcc, developer tools, and extras. I am trying to compile a
> > simple C program, with no luck.
>
> You say you installed gcc and *also* the developer tools? Perhaps that's
> your problem. The developer tools already include a working gcc. If you
> attempted to install a different gcc and didn't get it right, perhaps
> that explains the problem you are having.

I installed the gcc-4.0 package from the Xcode package. There is no
explanation of any of the many packages in teh gigabyte-big Xcode
download. How am I supposed to know what includes what? Is there any
way to uninstall them, if you feel one of them may be causing a
problem?


>
> > $ cat try.c
> > #include <stdio.h>
> > int main() {
> > printf("hello world\n");
> > return 0;
> > }
> > $ gcc try.c
> > try.c:1:19: error: stdio.h: No such file or directory
>
> Try "ls /usr/include/stdio.h". There are two possibilities. If the file
> does not exist, then you didn't install the developer tools. If the file
> exists but gcc can't find it, then you are not using /usr/bin/gcc, which
> is the version installed with the developer tools, but some other gcc
> instead. Where did you get this other gcc?
>

I got gcc from the gcc-4.0 package included in the Xcode package.


> > try.c: In function 'main':
> > try.c:4: warning: incompatible implicit declaration of built-in
> > function 'printf'
>
> Try "which gcc". You should get /usr/bin/gcc. If you get something
> else, then repeat the experiment, using "/usr/bin/gcc try.c" in place of
> the above.
>

$ which gcc
/usr/bin/gcc
$ ls -ltr /usr/bin/gcc
lrwxr-xr-x 1 root wheel 7 Mar 26 21:44 /usr/bin/gcc -> gcc-4.0

> > $ gcc -I /Developer/SDKs/MacOSX10.4u.sdk/usr/include/ try.c
> > /usr/bin/ld: can't locate file for: -lcrt1.o
> > collect2: ld returned 1 exit status
> > Help.. what's next?
>
> Apple's gcc works. You must have done something to mess it up.

Surely the fault is all mine. I guess I'm used to having all the
compilers working out of the box.

Tom Harrington

unread,
Mar 30, 2007, 12:31:52 AM3/30/07
to
In article <1175224290....@b75g2000hsg.googlegroups.com>,
san...@gmail.com wrote:

> On Mar 29, 10:50 pm, Dave Seaman <dsea...@no.such.host> wrote:
> > On 29 Mar 2007 19:25:56 -0700, sand...@gmail.com wrote:
> >
> > Try "ls /usr/include/stdio.h". There are two possibilities. If the file
> > does not exist, then you didn't install the developer tools. If the file
> > exists but gcc can't find it, then you are not using /usr/bin/gcc, which
> > is the version installed with the developer tools, but some other gcc
> > instead. Where did you get this other gcc?
> >
> I got gcc from the gcc-4.0 package included in the Xcode package.

GCC is a compiler. Header files are not part of the compiler.

> > > $ gcc -I /Developer/SDKs/MacOSX10.4u.sdk/usr/include/ try.c
> > > /usr/bin/ld: can't locate file for: -lcrt1.o
> > > collect2: ld returned 1 exit status
> > > Help.. what's next?
> >
> > Apple's gcc works. You must have done something to mess it up.
> Surely the fault is all mine. I guess I'm used to having all the
> compilers working out of the box.

They do work out of the box, but you have only installed the compiler,
not the necessary header files. GCC probably works fine but it can't
help you if you don't install the headers you're including.

The normal approach is to just run the Xcode installer, which will give
you the option to customize your install. If you want to cherry-pick
the individual package installers, that's your business, but you're kind
of on your own for figuring out which ones you need.

The header file in this case is included in the DevSDK package. However
I have no idea what else you might be missing if you go ahead and just
install that. Do yourself a favor, use the Xcode installer. If you
don't, be prepared to continue running into missing files and unexpected
problems.

--
Tom "Tom" Harrington
MondoMouse makes your mouse mightier
See http://www.atomicbird.com/mondomouse/

Michael

unread,
Mar 30, 2007, 12:52:47 AM3/30/07
to
On Mar 29, 9:11 pm, sand...@gmail.com wrote:
> On Mar 29, 10:50 pm, Dave Seaman <dsea...@no.such.host> wrote:
>
> > On 29 Mar 2007 19:25:56 -0700, sand...@gmail.com wrote:
>
> > > I just got my first mac (a macbook), after using Linux for many
> > > years. Seems like it takes a lot of effort to get up an environment
> > > that can build things, such as open source packages. I've downloaded
> > > Xcode and installed some packages that looked like they made sense,
> > > including gcc, developer tools, and extras. I am trying to compile a
> > > simple C program, with no luck.
>
> > You say you installed gcc and *also* the developer tools? Perhaps that's
> > your problem. The developer tools already include a working gcc. If you
> > attempted to install a different gcc and didn't get it right, perhaps
> > that explains the problem you are having.
>
> I installed the gcc-4.0 package from the Xcode package. There is no
> explanation of any of the many packages in teh gigabyte-big Xcode
> download. How am I supposed to know what includes what? Is there any
> way to uninstall them, if you feel one of them may be causing a
> problem?

It sounds like you are trying to selectively install the packages.
There was an XcodeTools.mpkg installer at the root level of the Xcode
disk image. It is a meta installer and will run the individual
installers within the Packages folder, and is the proper way to
install the developer tools. It also does nice things like dependency
checking... You can customize the install, which is what I am guess
you were trying to do by manually installing packages from the
packages folder.

In any case, the header files and libs like crt1 are in the DevSDK.pkg
installer, which should have been installed automatically if you had
used the XcodeTools.mpkg. I would go back and install the stuff
through the XcodeTools.mpkg.

Michael

san...@gmail.com

unread,
Mar 30, 2007, 1:13:25 PM3/30/07
to


Thanks - this looks like it worked!

0 new messages