Compiling a simple .c file on Unix Terminal

Belaran

Registered
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%
 
change your definition of main to:

Code:
int main(int argc,char *argv[])

and at the end of main put:

Code:
return 0;

and remove the double sets of brackets (this shouldn't hurt, but they're not needed).
 
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.
 
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
 
Essaie ça :

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

int main (int argc,char *argv[])
{
printf( "Bienvenue sur WORDPAD\n\n");
return 0;
}
 
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...)
 
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
 
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:~] 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 !
 
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.
 
Back
Top