How to compile a c program by using gcc

Hi all,

Yeasterday I try to compile c program by using cygwin. I just find an errors the fist one is concerinig about the end of the line.

To summit my Assignment which is the day after tommorow I have to compile my c program by using just gcc.

If any one know what do I have to exclude or include in a code over the program that workes on visual c++? I need Help?

Titie,

  1. this forum is really not for homework

  2. if gcc reports syntax errors, that means the code needs to be changed.

  3. gcc myfile.c compiles C code not C++ code.

  4. g++ myfile.cpp compiles C++ code

C++ and C are very different languages, compilers that expect C (gcc) will not compile C++ code.

Just use

gcc -o file file.c

it will create an file.exe

and then run it as

./file.exe

Sorry Sanju but u have mixed up Unix file format ( aout , coff , elf and as86 ) with that of Windows. Compiling the file as u said (gcc -o file file.c) wont create file.exe but rather create an output file with the name 'file' only. And u can run that like ./file
U may even skip '-o ' option in gcc and that will produce an output file named a.out that can be run as ./a.out (Though the native format of Linux is ELF in this case it produces output file of aout format)
And as for Bell plz. follow jim's advise.

I know this is way late for your assignment, but I'm new to the forum. All I was going to add is this "end of line" error probably has to do with your Visual code using DOS CarriageReturn+LineFeed (0x0D0A respectively) for end of record delimiter while Linux (even psuedo-Linux like cygwin) uses just newline (0x0A). (Actually, I think Cygwin has an option for CRLF, but that's another matter.) You can use the Unix translate utility, "tr," to axe the extra character, i.e. ixnay the CR, like so:
tr -d '\r' <dosfile_crlf.c >unixfile_nl.c

Hope this proves helpful in the future since I was not in time for your assignment.
~Marcus

ok, this is sort of a misconception. gcc compiles both. I just finished an ADMIN control area in C++ with the .cpp extension and compiled it with gcc without problem. but in response to the actual problem here, id just use this line.
we'll call the source EXAMPLE.cpp, and the output will be EXOUT."file".

gcc -lg++ -Wall -pedantic -ansi -g -o EXOUT EXAMPLE.cpp

this is a good choice for debugging and compiling, it calls upon the normal system area for #include header files, uses the Wall function for the debugging side of things, ansi for ..... ansi compatibility i think and the -o gets rid of the a.out leaving you with the desired file, with the blank extension for linux/Unix.... hope that helped..Pe@cE