PDA

View Full Version : Am I being stupid?



Owain_Parry
July 19th, 2014, 04:17 PM
Hi, I'm trying to use GCC to compile a program, but when I run it in the terminal I get no output. The program is:


#include <stdio.h>

int main()
{
printf("Hello, World!\n");

return 0;
}


and to compile it I typed 'gcc -o test main.c'. However when I run the program in the terminal I don't see anything. Have I done something wrong?

steeldriver
July 19th, 2014, 04:53 PM
If the program compiles successfully, gcc will not output anything in the terminal - however it should have produced a file called 'test' in the current directory

Owain_Parry
July 19th, 2014, 04:57 PM
Sorry, prehaps my wording wasn't clear. When I run test in the terminal I don't get any output. I don't see 'Hello, World!', as I was expecting.

trent.josephsen
July 19th, 2014, 05:17 PM
test is a shell command:

$ which test
test: shell built-in command

Type ./test to make sure you're running the file in the current directory.

Owain_Parry
July 19th, 2014, 05:23 PM
Thankyou!

ofnuts
July 20th, 2014, 12:32 AM
This is automatic hazing put in Unix from the origins. Every Unix user is bitten by this at least once. You got your first badge, welcome to the club :)

donkyhotay
July 21st, 2014, 10:03 PM
You're not stupid, it's an easy mistake. Test is such an obvious name for a first program, but is actually a pretty bad choice because there is a program called test. For future reference, when coming up with the name of something try typing it into bash first to make certain something else doesn't use it already use it. Or if you really want the name to be something specific, just remember to put a ./ in front of it to specify the program.