Compiling using cc generates cc: no input files
Hi All,
I was following a very basic tutorial on how to compile programs for linux using gcc and cc When I compile and run the test program below, using the command gcc program.c -o program everything works fine. #include <stdio.h> int main() { printf("Hello World\n"); return 0; } If I try compiling using the following commands it generates an error relating to having no input file: cc program.c cc -o program.c Error: cc: no input files I must be missing something very basic here? Regards Patrick |
Does the first one give the error as well? If so, are you compiling in the directory where program.c is stored?
For the second one, -o specifies the output file. So you actually did not specify any source files to be compiled. Code:
fortyfourgalena@desktop-01:~$ ls *.c |
The first one compiles and runs okay and I'm compiling within the tmp directory where the source file is located.
The second approach generated the file 'program.o' after executing the command 'cc program.c' The tutorial stated that after running the above file to execute the command cc -o program.c I take it that this is not the correct syntax? What would be the correct syntax of the commands if I wanted to compile a program.c in the tmp folder and link it afterwards? Patrick |
I know for gcc it's the following
Code:
gcc -o program program.c |
Quote:
You quoted incorrect instructions from the tutorial. I think it would help if we could look at the tutorial and tell you whether you misunderstood what it said vs. the information there is incorrect. |
|
They are wrong; read man cc. Look for the -o option; the argument following it is the name of the output file.
Code:
-o filename |
Thank's for pointing me in the right direction, I was assuming that cc and gcc were two different compilers but on my system cc seems to be just a pointer to gcc and takes the same command line options.
Patrick. |
Quote:
Quote:
cc -o first first.c that was just mistyped. Even without that error, the post is misleading, since it doesn't explain why a beginner might ever want the first command (which creates only an object file) vs. the second command that creates an executable. So it is easy to see how electriceddy misunderstood and thought the second command was for use after the first command rather than instead. Quote:
gcc -c program.c gcc -o program program.o The first step creates program.o. The second step uses program.o to create program. It leaves program.o so you have both program and program.o when you're done. The single step version is gcc -o program program.c That compiles (creating the .o file) and links (creating the executable from the .o) then deletes the .o. |
All times are GMT -5. The time now is 11:19 AM. |