The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compile a c program djehresmann High Level Programming 8 02-22-2008 10:18 AM
Compile and Run C Program on Solaris selva_ss High Level Programming 0 02-21-2008 10:52 AM
How to compile a c program in freeBSD jisha BSD 3 02-13-2008 12:14 AM
how to compile a program statically bhakti High Level Programming 1 07-31-2006 07:01 AM
how to compile a program CmpKillr High Level Programming 2 04-07-2003 02:57 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-04-2006
Registered User
 

Join Date: Apr 2006
Posts: 1
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,
Reply With Quote
Forum Sponsor
  #2  
Old 04-04-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
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.
Reply With Quote
  #3  
Old 04-08-2006
Registered User
 

Join Date: Apr 2006
Posts: 1
Cool gcc

Just use

gcc -o file file.c

it will create an file.exe

and then run it as

./file.exe
Reply With Quote
  #4  
Old 04-09-2006
Rakesh Ranjan's Avatar
Registered User
 

Join Date: Aug 2005
Location: India
Posts: 40
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.
Reply With Quote
  #5  
Old 04-26-2006
Registered User
 

Join Date: Apr 2006
Location: Massachusetts
Posts: 9
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
Reply With Quote
  #6  
Old 05-14-2006
01000101's Avatar
Registered User
 

Join Date: May 2006
Posts: 15
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0