# [SOLVED] Code::Blocks can't build and run '.c' files



## Jamsers

Hello everyone. I just switched to Ubuntu 10.10 64 bit from Windows 7 and so far, it's been lovely. Everything I needed was there, and I got all my software from the Ubuntu Software Center.

But, I have a big problem right now. I'm a Computer Science student, and am extremely new to programming.

I installed Code::Blocks using the Ubuntu Software Center.

I make a simple "test.c" file, put some code into it, open it using Code::Blocks, and hit the "build and run" button, just like the way I did on Windows. But, it doesn't run. A dialog box pops up and says "It seems the file hasn't been built yet. Would you like to build it now?". I hit yes, and the dialog box pops up again. The program never runs.

In Windows, it did.

I look at the folder where my "test.c" file is located, and I see there is now a "test.o" file, but no "test.exe" file, like there was in Windows.

Please help me. I am completely helpless right now. I've tried Googling for an answer, but I can't find one.

I don't really mind if I don't get the ".exe" file or whatever. What's important to me right now is I get my ".c" files to "build and run", just to see how it runs.

Thank you in advance for any help you can give me. I like Ubuntu, and I can't stand going back to Windows just for this very reason, when everything else about this OS is pretty good.


----------



## Ninjaboi

*Re: Code::Blocks can't build and run ".c" files*

Try creating a file named "hello.c" with the data:



Code:


#include <stdio.h>

main()
{
  for(;;)
      { 
          printf ("Hello World!\n");
      }
}

Try to compile that and see if you can run it. Just to give you another tip, executable files are for Windows, not Linux. You should be able to run your program by going through the terminal as well if I'm not mistaken.


----------



## Jamsers

*Re: Code::Blocks can't build and run ".c" files*

Thank you for the reply Ninjaboi, I really appreciate it. So I tried your code, and the same problem: it compiles, no problem, but I can't get it to run.

Maybe this will help...

Build log:
Compiling: /home/jamsers/Documents/Stuff for studies/CSC101/CodeTest.c
Linking console executable: /home/jamsers/Documents/Stuff for studies/CSC101/CodeTest
/bin/sh: g++: not found
Process terminated with status 127 (0 minutes, 0 seconds)
0 errors, 0 warnings

Build messages say nothing. Anyways, thanks for the heads up about ".exe" not being for Linux, hehe, I guess I saw that coming. I've installed Wine to alleviate that problem.


----------



## Ninjaboi

*Re: Code::Blocks can't build and run ".c" files*



> /bin/sh: g++: not found


You apparently don't have g++ installed ( or at least installed correctly ) on your system. In other words, you have the IDE ( Code::Blocks ) ready to go, but the compiler itself is not.

Try either installing the Gnu Compiler Collection (gcc) , or try to completely uninstall and reinstall Code::Blocks, as it should provide this for you already.

That simply explains why you can 'compile' with no errors but can't run it. You have no compiler to do the compiling, and therefore it cannot produce errors ( for there's no compiler to check for these errors ).

Hope that made sense.


----------



## Jamsers

*Re: Code::Blocks can't build and run ".c" files*

Wow, thanks! That actually makes a lot of sense... thank you, hehe. I installed Code::Blocks using the Ubuntu Software Center though, and that's supposed to install all dependencies... so I'm still at a bit of a loss why GCC wasn't included. Then again, when it was installed, it didn't ask for the default compiler, like it did in Windows, so like I said, that makes a lot of sense.

I'm gonna try looking for the GCC compiler to see if it fixes it. This was the default compiler I used in Windows, and it worked perfectly.

For now, I've resorted to installing a Windows version of Code::Blocks using Wine, and it compiles my files. But I can't run directly from within Code::Blocks, which is a major hassle.


----------



## Ninjaboi

*Re: Code::Blocks can't build and run ".c" files*

That would be inconvenient, I do hope that fix I suggested works then.


----------



## Jamsers

*Re: Code::Blocks can't build and run ".c" files*

It works flawlessly! I searched for the GCC compiler for Code::Blocks from the Ubuntu Software Center, checked it, installed, and now I can "build and run" flawlessly! Thank you Ninjaboi, problem solved.


----------



## Ninjaboi

*Re: [SOLVED] Code::Blocks can't build and run &quot;.c&quot; files*

No problem.

Happy coding!


----------

