I am running an Ubuntu v10.04 through VirtualBox. To test the persistence of files I create in the virtual machine, I wrote a very basic C program. When I shutdown the virtual machine and restart it, I see that the files have been retained.

What happens:

  • I can check the directory with ls /root/ and see both program_name.c and the compiled program_name

  • I use this command to compile: gcc program_name.c -o program_name

  • I can run ./a.out and the program will execute properly.

  • Opening the C code with nano program_name.c shows the program, as I expect it to be.

The problem is...

  • When I try to the program via ./program_name, nothing happens!

  • If I check the exit status (echo $?), it is zero.

    I am having difficulties understanding why I can't run the compiled C program, even though I can find it. It is most bizarre to me considering I can locate all the files AND ./a.out executes it properly.


Edited for clearer presentation.

Edit regarding answer...

In the off chance that someone else comes to this looking for help, it should be noted that while the file program_name command did expose that the file was blank, the cause hasn't been determined. I successfully ran the executable before I restarted the virtual machine.

Perhaps I didn't shut down the virtual machine properly? Anyways, checking the file was/is certainly helpful!

  • What command line are you using to build the program? If you're using cc program_name.c you will get an a.out file; try cc -o program_name program_name.c, then. – Renan Feb 16 '13 at 23:54
  • @Renan I am using gcc as that is what I am accustomed to. gcc program_name.c -o program_name – d0rmLife Feb 17 '13 at 0:03
  • 1
    @d0rmLife with the -o flag passed to compiler, you specify the name for the output file as prog_name. I'd suggest reading the man page for gcc with command man gcc, which will help you use it better and learn quickly. – user27225 Feb 17 '13 at 0:05
  • @G.Kayaalp Is that not indicated by how I input it? I have used that convention for other linux systems as well as OSX with no problems. – d0rmLife Feb 17 '13 at 0:05
  • Maybe you can upload the source code somewhere for inspection? – daisy Feb 17 '13 at 1:08

Since you're using the -o option to rename the compiled program, the a.out you have there now belongs to something else (earlier version or something completely unrelated).

Your program probably is running but just isn't returning any output. Check the file size and run file program_name to convince yourself that it's an executable then see what the code should do -- take an argument perhaps.

  • 1
    Btw, the title is misleading since this doesn't involve ".o" (object) files. – igelkott Feb 17 '13 at 1:10
  • You are correct, the file was corrupted somehow. Considering I executed the file before I restarted the virtual machine, I'm not exactly sure why that happened. I will vote you up when I acquire the requisite rating. – d0rmLife Feb 17 '13 at 2:13
  • Maybe cache was not written to disk. Did you shut down the VM cleanly? – ali1234 Feb 17 '13 at 5:14

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.