How to compile a c program by using gcc | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

How to compile a c program by using gcc

Programming


Tags
linux

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-04-2006
Bell Bell is offline
Registered User
 
Join Date: Apr 2006
Last Activity: 4 April 2006, 10:24 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question 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,
Sponsored Links
    #2  
Old 04-04-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 20 October 2014, 6:07 PM EDT
Location: NM
Posts: 10,240
Thanks: 281
Thanked 803 Times in 747 Posts
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.
Sponsored Links
    #3  
Old 04-08-2006
sanju23jan sanju23jan is offline
Registered User
 
Join Date: Apr 2006
Last Activity: 8 April 2006, 4:13 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Tools gcc

Just use

gcc -o file file.c

it will create an file.exe

and then run it as

./file.exe
    #4  
Old 04-09-2006
Rakesh Ranjan's Avatar
Rakesh Ranjan Rakesh Ranjan is offline
Registered User
 
Join Date: Aug 2005
Last Activity: 18 December 2009, 8:29 AM EST
Location: India
Posts: 42
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by sanju23jan
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.
Sponsored Links
    #5  
Old 04-26-2006
marcus121 marcus121 is offline
Registered User
 
Join Date: Apr 2006
Last Activity: 5 June 2009, 3:11 PM EDT
Location: Massachusetts
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Bell
I just find an errors the fist one is concerinig about the end of the line.
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
Sponsored Links
    #6  
Old 05-14-2006
01000101's Avatar
01000101 01000101 is offline
Registered User
 
Join Date: May 2006
Last Activity: 2 July 2006, 3:53 PM EDT
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by jim mcnamara
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.
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Not able to compile C program on z/OS (USS) madhu84 Programming 7 06-21-2011 11:03 AM
Can someone compile and run a program on AIX 6.1 please? StuBob Programming 2 03-09-2011 06:28 AM
Compile c program on Sun Solaris OS shivu Programming 4 02-04-2009 09:58 AM
compile a c program djehresmann Programming 8 02-22-2008 12:18 PM
how to compile a program CmpKillr Programming 2 04-07-2003 05:57 PM



All times are GMT -4. The time now is 08:00 AM.