LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-26-2007, 06:26 PM   #1
WindsorKnot
Member
 
Registered: Aug 2005
Location: Minneapolis
Distribution: Ubuntu 14.04
Posts: 36

Rep: Reputation: 15
GCC baptismal for DevShed brat


RH9 was contentedly installed on my Tecra 8000 less than 48 hours ago; and I want to make sure I've got the tools I need to set it up further to suit my needs. I wrote a "Hello world" C program and tried compiling it from the shell prompt. This created a file called a.out, whose "properties" box says it's a binary app; except I can't execute it either by double-clickus or from the shell prompt. I linked a.out, calling the output file "hithere" but I have the exact same problem. (Not even sure if linking is necessary when the only external call is an #include to stdio.h.)

I want this laptop to be a TFTP server. No such daemon seems included with the install. At the moment I'm not confident that if I find the right open-source one, that I can be trusted to compile it properly.

Where's the "Gcc for newbies" tutorial?
 
Old 03-26-2007, 07:12 PM   #2
Gato Azul
Member
 
Registered: Sep 2003
Location: /dev/null
Distribution: CentOS, Ubuntu
Posts: 128

Rep: Reputation: 16
What were the exact commands that you used to compile your program and attempt to execute the binary? Also, what are the permissions on the binary that gcc created?

I guess as an example for how I would do it, if I wanted to compile my file helloWorld.c into a binary executable called hello, I would run the following command (everything after the $ sign):

Code:
[gatoazul@computadora ~]$ gcc -o hello helloWorld.c
Then instead of the a.out file, I'll have an executable named hello:

Code:
[gatoazul@computadora ~]$ ls -l
total 12
-rwxr-xr-x 1 gatoazul users 6440 Mar 26 18:54 hello
-rw-r--r-- 1 gatoazul users   91 Mar 26 18:54 helloWorld.c
The first set of permissions (the bolded letters in the -rwxr-xr-x part) on the hello file are critical when it comes to me executing the file. The next set shows what those in my group can do, and the last set shows what others can do. The rwx for me as a user shows me that I can read, write, and execute the file. If you don't have execute permissions on your file, you can easily set it so that you do (and if you do have execute permissions, then ignore this step):

Code:
[gatoazul@computadora ~]$ chmod u+x hello
Now to execute hello, you'll prefix it with a ./
Code:
[gatoazul@computadora ~]$ ./hello
hello, world!
The ./ tells the shell to look in the current directory for the file (or folder) that follows the / and if you have execute permissions, it will execute that file. In this case, the shell executes the binary file called hello that we compiled.

I guess I'm not aware of any quick start guides to GCC, but I'm sure Google could come up with some pretty easily. You might want to take a look at the official GCC documentation -- it's quite good and very thorough:
http://gcc.gnu.org/onlinedocs/

Sorry if my quick little tutorial was either too simplistic or unclear at all...just let me know though if you don't understand something and I can fix it or explain it better.

Hope that helps!

Last edited by Gato Azul; 03-26-2007 at 07:19 PM.
 
Old 03-26-2007, 07:12 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
http://www.gnu.org is the place to look for the GNU gcc manuals. http://gcc.gnu.org/onlinedocs/ for on-line reading.
 
Old 04-27-2007, 07:15 PM   #4
WindsorKnot
Member
 
Registered: Aug 2005
Location: Minneapolis
Distribution: Ubuntu 14.04
Posts: 36

Original Poster
Rep: Reputation: 15
Thank you both for that excellent information; especially Gato Azul - it worked!

I just didn't get (and still don't, conceptually) the whole "./" thing. (I mean why should the shell need to be told to search the _current_ directory; what the heck else is there to search...)

Anyway, thank you. I have lots of happy coding time ahead of me now.
 
  


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
Oh no,,, it's another snot nosed, teenage, high school brat! demosthenes2 LinuxQuestions.org Member Intro 2 09-24-2005 01:54 PM
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare SUSE / openSUSE 3 11-29-2004 02:13 PM
Kernel compiling: gcc-3.3 is 586, should be gcc-3.3 386 Erik Plaggenmar Linux - Software 0 10-01-2004 11:38 AM
a doubt with host gcc and arm-linux-gcc renjithgopal Linux - General 1 09-11-2003 04:02 PM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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