Solved

Failure to Output Hello

Posted on 2008-10-29
11
327 Views
Last Modified: 2012-05-05
Hello Experts,

I have been looking compiler directory like crazy. Pleave provide pointing for solutions?

Looked @ gcc.c-torture dir with compile and execute folders.

It didn't run in any folders. Should I need to configure something?

gcc -o hello.c
gcc -v hello.c
===============================
#include <stdio.h>
main ()
{
printf("Hello World\n");
}

Please advise, help?
0
Comment
Question by:suredazzle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22838662
Put the code you posted (with a small modification - see below) in a file with .c extension (for example, hello.c).

Navigate to the directory that contains that file, and play these commands to compile the code into an executable :

        gcc -c hello.c -o hello.o
        gcc hello.o -o hello

The first creates the object file, the second links all object files (just one in this case) into an executable called 'hello'.

Now, you can run the code this way :

        ./hello

and, assuming all previous steps succeeded, you should see "Hello World" printed on your screen.

If not, please post the output of all commands, as well as any errors you get.
#include <stdio.h>
 
int main (void) {                        /* <--- main HAS to return int */
    printf("Hello World\n");             /* <--- always properly indent your code */
}

Open in new window

0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 22842838
I believe that if you ran "gcc -v hello.c", then it will generate an executable in the default file "a.out".  Check if you have an a.out.  But it's generally best to do it like Infinity08 said, in two stages.

Running "gcc -o hello.c" doesn't make much sense.  That's telling gcc to put its output into "hello.c", overwriting the existing hello.c.  It also doesn't give gcc any input files.  So in the end it takes no action.

0
 
LVL 1

Accepted Solution

by:
suredazzle earned 0 total points
ID: 22846556
Hi NovaDenizen & Infinity08,

Include .bash_profile:
CPATH=/....../execute/hello.c

Bin is empty folder. There is no reason to put above.

.bash_profile return no error.

2nd, I changed ..../compile/hello.c

gcc -v  ----> no version output
gcc -c hello.c
gcc hello.c

Command not found. I don't understand.

I gzip the gcc file.

Compile directory of gcc has simd, nested, pointer, init, and etc files.

So, I am lost at this point of configuration gcc.

Please advise or pointing solutions, NovaDenizen & Infinity08.

Linh
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 200 total points
ID: 22846575
So, if I understand it correctly, gcc was not (correctly) installed ?

Here's everything about how to correctly install gcc :

        http://gcc.gnu.org/install/
0
 
LVL 22

Assisted Solution

by:NovaDenizen
NovaDenizen earned 200 total points
ID: 22846861
I don't think you're ready to compile and build gcc yet.  Are you using linux?  If you are, whatever distribution you're using should have a way of downloading and installing gcc mostly automatically.
0
 
LVL 1

Author Comment

by:suredazzle
ID: 22847052
Hi Nova Denizen & Infinity08,

Well, the file should be in the compiler directory or pointing to it.
Just like you run .html in /www.

This scenario, I am not doing make unless it's installer.

2nd, gcc is not compatible for Mac OS. I looked at machine list, IMAC is not listed. Only PowerPC, which it is Darwin-OS Server.

Why should it matter?  Sun Solaris, PowerPC & Mac OS are based Unix compatible, right?

Mac OS is different family like HP-UX.

Let me see if there's better gcc. If not, there is Xcode.

Thanks guys for your help! I really appreciated it.
0
 
LVL 1

Author Comment

by:suredazzle
ID: 22847487
Hi Nova Denizen & Infinity08,

Mac OS doesn't install gcc compiler. Only Xcode tool.

http://www.tech-recipes.com/rx/726/mac-os-x-install-gcc-compiler/
0
 
LVL 1

Author Comment

by:suredazzle
ID: 22847562

Warning: 1GB Available

Before install, validate hard drive

1. df -h
2. screen shows 686. I think.
3. Reject less than that.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22848057
suredazzle, with the way you provide information, it has been very difficult to figure out what your problem was. And I'm actually still not sure what it is. In the future, if you ask another question, you need to be very clear about what the problem is, and describe it in as much detail as possible. Do not assume that the people reading your question can also read your mind or look over your shoulder, because they can't ;)
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 22851221
It looks like xcode is the way to go.  If you don't have enough disk space, then that's a problem you have to solve before you install gcc.  If the xcode package is a whole gigabyte then it sounds like there is more than just gcc in the package, but I don't see how you can get gcc otherwise.
0
 
LVL 1

Author Comment

by:suredazzle
ID: 22852246
Hi Infinity08 & NovaDenizen,

Sorry, I apologize for miscommunication. Next time, I will clarify question in better ways.

Darn right, I have enough disk space. You get the GCC, another application, and etc.

Downloaded Xcode last night.

Let's rollback, the GCC from the site. Just didn't work.

Good thing, keep the surprise. :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is sub-make ? 2 108
How to learn Linux? 10 99
Secondary drive is failing... D Volume 11 99
NEED to remove from column B the value in column C 6 17
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question