newbie gcc question

Konstantinos Adamopoulos kadamopo@comp.brad.ac.uk
Wed Oct 13 22:53:00 GMT 1999


I don't know what kind of system you are using (unix, linux or what),
but anyway here are some suggestions to try:
1. I have never tried Z shell myself. Maybe you should switch to
a different shell by using one of the following commands and then try to
execute your program again:
    csh       
-- to run c shell
    bash       --
to run bash shell
    ksh       
-- to run korn shell
2. If the current directory is not in your path you should always
use ./filename to execute your binary files, for example
    ./a.out
3. Check if the output file (a.out) is executable. Use the command
    ls -l
and you should have a line like the following one for your a.out
file
-rwx------   1 kadamopo 1UGCS4     
6776 Oct 14 06:13 a.out
The important bit is the x (4th characters), which means that your
file is executable. If is not there give the command:
chmod 700 a.out
in order to make your file executable
4. Maybe your compiler is confused with the extension of your file
name, for example .c mean c program, and usually .C or .cpp means c++ program.
In a c program usually you can't use expressions like
void main()
because this is specific for c++ programs and the c compiler is
expecting a returned value. It is better to use something like
  #include <stdio.h>
int main()
{
    printf("Hello, world!");
        return 0;
}
or to rename your file to something like helloworld.cpp or helloworld.C
and try it with its original contents without to change anything.
------------------------------------------------------------------------------------------------------
To conclud:
Your program seems to work fine in my system (running Sun OS and gcc-2.95)
as it is
  #include <stdio.h>
  void main()
  {
    printf("Hello, world!");
  }
when I save it as helloworld.cpp and compile with
gcc helloworld.cpp (then run ./a.out)
or
gcc helloworld.cpp -o helloworld (then run ./helloworld)
When I save it as helloworld.c needs the modification I mentioned before,
and looks like this:
#include <stdio.h>
int main()
{
    printf("Hello, world!");
        return 0;
}
compile with
gcc helloworld.c (then run ./a.out)
or
gcc helloworld.c -o helloworld (then run ./helloworld)
------------------------------------------------------------------------------------------------------
Hope that's a bit of help,
Kostas
 
Maggie Owens wrote:
I have a little experience writing C++ in the dos
and windows
environment. Now I am trying to write a c program and compile it in
gcc
on a unix system. As a test, I wrote the traditional hello, world
program:
  #include <stdio.h>
  void main()
  {
    printf("Hello, world!");
  }
I compiled it using:
  gcc helloworld.c
Now, I have a.out, which appears to be executable.
I am using the z shell.
I tried typing:
   a.out
and got:
   zsh: command not found: a.out
so I tried
   sh a.out
and got
   a.out: (M-^A)^C^A^K: not found
   a.out: syntax error at line 10: `;;' unexpected
finally, I tried
   ./a.out
and got nothing in response
I feel abysmally stupid. How can I execute my program?
Thanks in advance
--
Autoreplies will (hopefully) bounce. To reply to me, please send mail
to mmowens at panix dot com.
Sent via Deja.com http://www.deja.com/
Before you buy.

--
====================================================
Konstantinos Adamopoulos
Final Year Student in Computer Science
Department of Computing - University of Bradford
----------------------------------------------------
Phone: +44 1274 238732
Fax  : +1 909 257 7791
email: kadamopo@comp.brad.ac.uk
WWW  : http://www.student.comp.brad.ac.uk/~kadamopo
====================================================
 



More information about the Gcc-help mailing list