# Compiling a simple .c file on Unix Terminal



## Belaran (May 1, 2003)

I'm beginning to work with C and i wanted to compile a very simple file :
#include <stdio.h>

void main (void)
{
	{
		printf( "Bienvenue sur WORDPAD\n\n");
	}
}
 with "cc main.C" and here what i got :

[Belaran:~/Desktop/Info/Langage C] belaran% cc main.c
main.c: In function `main':
main.c:4: warning: return type of `main' is not `int'
/usr/bin/ld: /usr/lib/libSystem.dylib load command 9 unknown cmd field
[Belaran:~/Desktop/Info/Langage C] belaran%


----------



## binaryDigit (May 1, 2003)

change your definition of main to:


```
int main(int argc,char *argv[])
```

and at the end of main put:


```
return 0;
```

and remove the double sets of brackets (this shouldn't hurt, but they're not needed).


----------



## Belaran (May 2, 2003)

I tried your code :
 but i still got this:
[Belaran:~/Desktop/Info/Langage C] belaran% cc main.c
/usr/bin/ld: /usr/lib/libSystem.dylib load command 9 unknown cmd field
[Belaran:~/Desktop/Info/Langage C] belaran% 

Moreover why my C interpreter refuse to acknowledge a simple program as the one i writed ? Because i'll need to start with very simple stuff.


----------



## lurk (May 2, 2003)

My google is a simple thing to use.  Off the first page I found this

If you get a message like: libSystem.dylib load command 9 unknown cmd field Then that means that you need to update your Developer tools to match the version of OS X which you are running. 

So the simple answer is that you are using the wrong version of the dev tools for your version of OSX.

-Eric


----------



## TME520 (May 6, 2003)

Essaie ça :

#include "stdio.h"
#include "iostream.h"

int main (int argc,char *argv[]) 
{ 
printf( "Bienvenue sur WORDPAD\n\n"); 
return 0; 
}


----------



## Belaran (May 8, 2003)

Thank you but i tried this i got over ten pages of errors !!!
I think i have the wrong version of the dev tools. But i don't know how to upgrade the one i got ( wich most likely 10.1). I hope to find some kind of FREE package on the macos site but i didn't find it ( this don't mean it isn't there...)


----------



## lurk (May 8, 2003)

The developer tools are free.   You can download them from the developer site at apple.  You just have to regester to get a login.

-Eric


----------



## TME520 (May 9, 2003)

Essaie plutôt ça, j'avais laissé des erreurs dans l'autre : 

#include "stdio.h" 
#include "iostream.h" 

int main (int argc, char* argv[]) 
{ 
printf("Bienvenue sur WORDPAD"); 
return 0; 
}


----------



## Belaran (May 9, 2003)

[Belaran:~] belaran% cc Desktop/test.c 
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:66: undefined type, found `class'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:67: undefined type, found `class'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:67: undefined type, found `class'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:91: undefined type, found `streambuf'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:92: undefined type, found `ostream'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:130: undefined type, found `class'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:130: illegal external declaration, missing `;' after `ios'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:130: undefined type, found `public'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:130: illegal external declaration, miss.... ect

thank anyway !


----------



## binaryDigit (May 9, 2003)

> _Originally posted by Belaran _
> *[Belaran:~] belaran% cc Desktop/test.c
> /usr/include/gcc/darwin/2.95.2/g++/streambuf.h:66: undefined type, found `class'
> ... *



I think the problem is that you are including iostream but your file is a .c file (which has no concept of a "class").

Simply remove the #include iostream.h from the file, you don't need it anyway.  Alternatively you can rename your file .cpp causing the c++ compiler to be invoked which should be happier.


----------

