LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-20-2011, 06:44 AM   #1
electriceddy
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Rep: Reputation: Disabled
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 08-20-2011, 07:04 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
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
ls: cannot access *.c: No such file or directory
fortyfourgalena@desktop-01:~$ gcc hallo.c
gcc: hallo.c: No such file or directory
gcc: no input files
fortyfourgalena@desktop-01:~$ gcc -o hallo.c
gcc: no input files
fortyfourgalena@desktop-01:~$
 
1 members found this post helpful.
Old 08-20-2011, 07:16 AM   #3
electriceddy
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-20-2011, 07:31 AM   #4
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 70
I know for gcc it's the following
Code:
gcc -o program program.c
My cc is linked to gcc. They should be using the same syntax. The -o designates what you what you want the finished product binary to be called.
 
1 members found this post helpful.
Old 08-20-2011, 07:47 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by electriceddy View Post
I was following a very basic tutorial on how to compile programs for linux using gcc and cc
Please provide the URL of that tutorial.

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.
 
Old 08-20-2011, 09:32 AM   #6
electriceddy
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Second post on this site archive.

http://ubuntuforums.org/showthread.p...ighlight=world

Patrick.
 
Old 08-20-2011, 10:46 AM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
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
	  Names	the output file	filename, instead of the  default
	  a.out.  filename cannot be the same as sourcefile since
	  cc does not overwrite	the source file.  This option and
	  its argument are passed to ld.
 
2 members found this post helpful.
Old 08-20-2011, 12:00 PM   #8
electriceddy
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-20-2011, 12:22 PM   #9
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by electriceddy View Post
That post says:
Quote:
cc -c first.c

This will create an object file, to create an executable file type in:

cc -o first.c
I'm sure that second command was meant to say
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:
Originally Posted by electriceddy View Post
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?
If you want compile and link to be two separate steps:
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.

Last edited by johnsfine; 08-20-2011 at 12:28 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
etags: no input files specified. tirengarfio Linux - Software 1 02-21-2010 09:38 AM
redirecting input from two files zhjim Linux - Newbie 2 08-07-2009 03:33 AM
kdevelop generates gs_ files in tmp folder why k.king Linux - General 2 04-04-2006 02:25 AM
UX: lp: ERROR: No (or empty) input files sburns76247 Linux - General 0 03-02-2005 07:48 AM
Input/Output errors on files Poetics Slackware 4 08-25-2003 05:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration