Code::Blocks not compiling?

This is a discussion on Code::Blocks not compiling? within the C Programming forums, part of the General Programming Boards category; This may be a trivial error that I'm not recognizing (just recently started using code blocks) but I can't seem ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    29

    Code::Blocks not compiling?

    This may be a trivial error that I'm not recognizing (just recently started using code blocks) but I can't seem to figure out why this C source file wont compile. I have other files which compile and run just fine so I don't know what the issue is. Very simple code:

    Code:
    //9-25-12
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main () {
    
    int numPlayers;
    
    printf("How many players are playing?\n");
    scanf("%d", &numPlayers);
    printf("%d players are playing", numPlayers);
    
    system("PAUSE');
    return(0);
    
    }
    When I press "Build and Run" nothing happens, when I press "run" it says "it seems that this file is not built yet, would you like to build now?". If I press yes, nothing happens. If I press no the console pops up and says returned 0 (0x0) execution time 0.000s with none of the printf's printed. What am I doing wrong? Thanks.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,717
    Did you create a project? Or are you just trying to compile a file without a project?

    Jim

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    Quote Originally Posted by jimblumberg View Post
    Did you create a project? Or are you just trying to compile a file without a project?

    Jim
    I went to File->New->File
    This launched a window asking for file type, I selected C/C++ source file, which launched the C/C++ source file wizard, the wizard basically just asks if it's a C or C++ file (I chose C) and then asks for the file name with full path which I picked from the browse file function (...).

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,717
    You should create a project, then add that file to this project.

    Jim

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    Quote Originally Posted by jimblumberg View Post
    You should create a project, then add that file to this project.

    Jim
    I created a project and put the source file into it, but now when I try to build and run it I get an error in the build log that says " 'Program2 - Debug' uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping... Nothing to be done". When I created the project I chose Intel C/C++ compiler.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,717
    Do you actually have the Intel C/C++ compiler? Normally you use the gcc compiler with Code::Blocks. What operating system are you using?

    Jim

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    Operating system: Win 7 Home premium SP1
    I only tried it with the intel one because I tried to put it in a project before using the GNU GCC compiler but got the same error message I am getting now about the invalid compiler toolchain thing. I can compile a separate program with no difficulty, how can I view which compiler it's using? Can I change the compiler on the one that isn't working or create a new project using the correct one?

    Edit: my operating system is also 64 bit

  8. #8
    Registered User
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    242
    Quote Originally Posted by UCFuser View Post
    Can I change the compiler on the one that isn't working...?
    Yes you can.

    From the top menu: project -> build options -> choose compiler from dropdown box. That's how you can check what the compiler for the other projects are. So if all else fails, start a new project and choose the correct compiler when creating the project.
    IDE: Code::Blocks | Compiler Suite for Windows: TDM-GCC (MingW, gdb)

  9. #9
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    Ok I looked at the file that does compile, but now it will run when I press the play button, but pressing the build and run button doesn't do anything? Maybe because it's already built? And the program that compiles isn't part of a project it is just a .c file so is it possible to see which compiler is used for it? I changed the compiler on the project to GNU GCC but received the "invalid compiler...toolchain not setup correctly..." message again

  10. #10
    Registered User
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    242
    If it works with the Intel compiler, then change it back to that, or copy the code into a new project set with the Intel compiler. CB(for Windows) might come with MingGW though, which is a Windows port of GCC. You can try choosing MinGW as the compiler. When using CB, you can press F2 to see the logs window. When you try to build a program that has already been built, you should see something like "Target is up to date. Nothing to be " in done in the build log. If you didn't have the build log open, then it would appear that nothing happens when you try to build.The toolchain message has to do with specifying the path to the relevant directories that the compiler needs to access, and depends on the compiler that you have chosen. If you have more CB related questions, you will probably get better answers here: http://forums.codeblocks.org/If all else fails, back up your c files, uninstall and reinstall CB, which will default back to original settings.
    IDE: Code::Blocks | Compiler Suite for Windows: TDM-GCC (MingW, gdb)

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    2,553
    Quote Originally Posted by cfanatic View Post
    If it works with the Intel compiler, then change it back to that, or copy the code into a new project set with the Intel compiler. CB(for Windows) might come with MingGW though, which is a Windows port of GCC. You can try choosing MinGW as the compiler. When using CB, you can press F2 to see the logs window. When you try to build a program that has already been built, you should see something like "Target is up to date. Nothing to be " in done in the build log. If you didn't have the build log open, then it would appear that nothing happens when you try to build.The toolchain message has to do with specifying the path to the relevant directories that the compiler needs to access, and depends on the compiler that you have chosen. If you have more CB related questions, you will probably get better answers here: http://forums.codeblocks.org/If all else fails, back up your c files, uninstall and reinstall CB, which will default back to original settings.
    Actually this in one question you are not likely to get better answers on the CB site asking.

    The normal cause is the user has no Compiler installed on their computer.

    In this case, it sounds like CB detected a compiler and made it the default compiler.

    IIRC, when compiling without a project the default compiler is used.

    I suggest trying to find out the default compiler.

    "Settings" -> "Compiler ..."
    Should have the "selected compiler" name at the top of the window that show up.

    Turning on "Full Compiler Logging" tends to help newbies; for directions read CB Wiki Link below
    FAQ-Compiling (errors) - CodeBlocks

    CB User Manual (I have never read it; started on CB before it was written)
    User manual


    Tim S.
    Last edited by stahta01; 09-26-2012 at 03:35 AM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  12. #12
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    I was able to fix the problem by uninstalling code::blocks and then installing the "mingw-setup.exe" version of the binary setup file. Thanks for the advice from everyone though!

  13. #13
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    Quote Originally Posted by UCFuser View Post
    Code:
    system("PAUSE');
    Mismatched quotes.

  14. #14
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    Quote Originally Posted by qny View Post
    Mismatched quotes.
    I was waiting for someone to point that out.

    (I didn't point it out because the compiler would report it if it were working in his IDE, and I think that was the main point of this thread).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some help using Code::blocks !
    By Saurav Kalita in forum C Programming
    Replies: 1
    Last Post: 06-17-2012, 11:05 PM
  2. Compiling GTK+ C Programs in Code Blocks
    By Flotonic in forum C Programming
    Replies: 5
    Last Post: 03-24-2011, 06:10 PM
  3. Code Blocks compiling problem
    By Lehsyrus in forum Tech Board
    Replies: 2
    Last Post: 07-13-2010, 02:28 PM
  4. code::blocks
    By wart101 in forum Tech Board
    Replies: 4
    Last Post: 01-15-2007, 06:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21