 |
 |
Hello World not displaying
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2003
Status:
Offline
|
|
I'm just playing around with gcc compiler in 10.3.
Here is my code:
#include <stdio.h>
main(){
printf("Hello, World!");
}
Here are my commands:
gcc test.c -o test
I'm editing my file commandline through pico
It compiles fine(It better!) but doesn't display anything when I run test. Any idea what I'm doing wrong?
Thank you
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jul 2002
Status:
Offline
|
|
When you execute "test", you're running /bin/test, a standard utility. Try executing "./test" instead.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2003
Status:
Offline
|
|
Thank you very much!
Is there any way to avoid this? How can I make it where I would just run the executable I assign without ./ ?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Your $PATH variable determines where the interactive shell finds files to execute. By default $PATH is /bin /sbin /usr/bin /usr/sbin. I added a folder to my HOME directory named bin and added /Users/craig/bin to my path by modifying the .tcshrc file in 10.2 and the .bashrc file in 10.3. Do a Google search on tcsh path is your are using 10.2 and bash path if your are using 10.3. There will be examples of what to do on several sites listed there.
HTH
Craig
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by ownersbox:
Thank you very much!
Is there any way to avoid this? How can I make it where I would just run the executable I assign without ./ ?
Yes is is possible using the aforementioned PATH variable but it is highly recommended that you don't make such a change.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by WJMoore:
Yes is is possible using the aforementioned PATH variable but it is highly recommended that you don't make such a change.
Just give your executable a unique name. Call it HelloWorld instead of test.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2003
Status:
Offline
|
|
Tried that, it is still looking in the bin.... I will just use ./ to avoid causing other issues
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2003
Status:
Offline
|
|
You can add '.' (the current working directory) to the PATH, but it is not recommended.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2003
Location: UK
Status:
Offline
|
|
Justification for not putting . in your path:
Imagine you navigate to a folder in which someone else has write access. They maliciously (or a virus) have placed an executable called 'ls' that does something nasty is that folder.
You go there, type 'ls', and the malicious program executes rather than just giving you a directory listing.
If you put . at the END of your path, rather than the beginning, this won't happen - but what happens if it's a common mistype, or it autocompletes... still dangerous. Anywhere in your path is still dangerous.
Just do ./a.out instead, it's safer and makes you think about what you're executing.
You might also want to put a \n in your Hello World, or it won't look right!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|