I'm running kubuntu 9.10 in VirtualBox, i wrote the simplest "hello world" program in C, the code compiles, i ran it through a debugger and it seems to run fine. the only problem is nothing gets actually printed to the console... any ideas ?

heres the code:

#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv) {
  printf("hello world");
  return 0;

i compiled it using:

gcc -c test.c -o test.o
gcc test.o -o test

i get no error messages.

  • What commands do you use? and specifically to run it ? – S.Hoekstra Apr 14 '10 at 15:57
  • are you getting any error mesages or is there absolutely nothing displayed?? – Diskilla Apr 14 '10 at 15:58
  • 1
    Craigs answer is the correct one. Hoekstras answer works but does not explain why you got an error. – Nifle Apr 14 '10 at 16:38
  • while this seems like a Stack Overflow question, it isn't really about the code, or the compiling, but about the execution (PATH). it should stay on Super User. – quack quixote Apr 14 '10 at 22:08

Your path has /usr/bin before .

Try running it as ./test

/usr/bin/test just exits with no output

  • +1 This is in my opinion the correct answer. I have been bitten by this problem myself. NEVER call your program test! – Nifle Apr 14 '10 at 16:33
  • +1 As this is the real answer to the question, where i only answered it by accident. – S.Hoekstra Apr 14 '10 at 16:38
  • 1
    Having . in your path at all is not common, so it's not really a matter it being "before". Invoking it with the path is the correct solution though. – Ignacio Vazquez-Abrams Apr 14 '10 at 16:50
  • 1
    It should be noted that test is a builtin in Bash and many other shells so it would be executed before /usr/bin/test (and test without specifying a directory or not in PATH or late in PATH). – Dennis Williamson Apr 14 '10 at 21:31
gcc -o helloWorld test.c

When compiling is done without errors


And your program should run, displaying hello world

That should work fine.

Even though this "works" the real answer is using ./ to run the executable in the current directory. Where else it would run /usr/bin/test. All credits to Craig :)

  • that worked! thanks :) im sorry if its a stupid question but why wasn't it necessary to compile the source to an object file first in this case? furthermore, why does it cause a problem ? – yurib Apr 14 '10 at 16:13
  • You're welcome. In this case it's not necessary. You can compile simple code like this directly into one executable. Object files are only used in more complex programs. – S.Hoekstra Apr 14 '10 at 16:17
  • I don't think the problem was how you compiled but the name of the executable. See my answer below. – Craig Apr 14 '10 at 16:20
  • You are probably right too, but it's not possible to execute an object file directly. That had to be fixed first. – S.Hoekstra Apr 14 '10 at 16:23
  • He built an executable note the second gcc line -- gcc test.o -o test builds test from test.o – Craig Apr 14 '10 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.