Thread: code won't compile even if exactly copied from ebook

  1. #1
    Registered User
    Join Date
    Mar 2013
    Location
    London, Ontario, Canada
    Posts
    13

    Question code won't compile even if exactly copied from ebook

    Hi to all,

    I recently downloaded the ' code:blocks ' file. After I tried some code the compiler stated there was an error with
    ' #include<iostream> '.
    Since I'm not a C++ programmer, right now, I'm confused. This was copied directly from the e-book I downloaded. After I uninstalled this program, I re downloaded it and now it comes up with a new error while opening Code-blocks.
    This new error states ' Can't find compiler executable in your configured search path's for GNU GCC compiler '

    Is there is anyone out there who'd be able to understand this problem, I'd appreciate any help.

    Cheers,

    David Hubbard

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Which setup file did you download from the Code::Blocks site?

    codeblocks-12.11mingw-setup.exe

    codeblocks-12.11mingw-setup_user.exe

    You should have picked one of these.

    Alternately, you can keep your current setup and just install a version of minGW say from TDM-GCC

    Then you go to Settings -> Compiler and make sure that GCC is set as default.
    Last edited by whiteflags; 03-23-2013 at 05:45 PM.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by whiteflags View Post
    Alternately, you can keep your current setup and just install a version of minGW say from TDM-GCC

    Then you go to Settings -> Compiler and make sure that GCC is set as default.
    If you, "install a version of minGW say from TDM-GCC".

    Settings -> Compiler and make sure that GNU GCC Compiler (is the selected Compiler) and, then make sure it is set as default.
    And, click on the "reset defaults" for CB to reset the selected compiler back to defaults.
    (This results in Code::Blocks searching for the Compiler; and, clearing any Compiler Customization)

    If you do NOT wish to clear the Compiler Customization do the below step instead.
    On the Toolchain Executable tab, click on the button "Auto-detect"

    Tim S.
    Last edited by stahta01; 03-23-2013 at 06:34 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by stahta01 View Post
    If you do NOT wish to clear the Compiler Customization do the below step instead.
    On the Toolchain Executable tab, click on the button "Auto-detect"
    Success of that does rely on a (detectable) compiler being installed.

    The general principle is that a compiler is required to compile code. An IDE (such as Code::Blocks) is not a compiler. It is a suite with a user interface for helping a person manage the build process, and it invokes other programs to perform particular tasks. A compiler is a separate program (or, technically, a suite of programs in its own right) that the IDE invokes to compile source code.

    If the IDE is to successfully compile code a compiler must be installed. Or the IDE must either be bundled with a compiler (so both IDE and compiler are installed together) or the developer must have a compiler installed and configure the IDE to use it. The setup programs codeblocks-12.11mingw-setup.exe (from the codeblocks site) bundles both IDE and a version of the mingw compiler together. The setup program codeblocks-12.11mingw-setup.exe only includes the IDE (so it is a smaller download, but more is needed to get it working).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Location
    London, Ontario, Canada
    Posts
    13
    GNU GCC Compiler is the selected compiler. The (set as default) button is shadowed, so is unable to be depressed. The startup error is gone, but when I try to compile, this error comes up.

    Fatal error: iostream: No such file or directory

    I downloaded ( codeblocks-12.11mingw-setup.exe)

    I'd like to thank you for any assistance.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Read the info on this link.

    FAQ-Compiling (errors) - CodeBlocks

    Remember the file extension matters: *.c is compiled as C file, *.cpp is compiled as C++ file.
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Mar 2013
    Location
    London, Ontario, Canada
    Posts
    13
    Thank you Tim S. That was the problem. The files were saved in a C format. Once changed another error came up. Don't worry, I found the remedy.
    The program doesn't like ' using namespace std ' line, but when I remove this line all works well. I thought I saw this line in the e-book Jumping Into C++ I downloaded.

    Now it's time to get into learning how to program with C++.

    Dave H

  8. #8
    Registered User
    Join Date
    Mar 2013
    Location
    London, Ontario, Canada
    Posts
    13
    Quote Originally Posted by DaveHubbard View Post
    Thank you Tim S. That was the problem. The files were saved in a C format. Once changed another error came up. Don't worry, I found the remedy.
    The program doesn't like ' using namespace std ' line, but when I remove this line all works well. I thought I saw this line in the e-book Jumping Into C++ I downloaded.

    Now it's time to get into learning how to program with C++.

    Dave H

    All the best will come to those who are willing to wait!

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Alright, could you compile something for me?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      cout << "Hello, world!" << endl;
      return 0;
    }
    C++ code - 9 lines - codepad
    As you can see, this works completely fine. When a compiler gives you an error or a warning, try to read it for understanding. It doesn't just "not like 'using namespace std' line, but there is something wrong with it that doesn't make the whole source file a well-formed program. A missing semi-colon perhaps? It's not possible for us to know, without the actual errors being posted, and with no code to look at.

    Deleting whatever is apparently wrong is not going to work long term. My $.02.

  10. #10
    Registered User
    Join Date
    Mar 2013
    Location
    London, Ontario, Canada
    Posts
    13
    I'm not sure, but today it accepts 'using namespace std;', I did notice that I had forgotten to put
    'return 0;'. maybe the program is trying to tell me to look at the program as a whole, and not as individual lines of code.
    Well all I can say is it's time to continue with the Jumping Into C++ e-book. Getting me ready to create a Sudoku 4X4 generating software program.

    Dave

  11. #11
    Registered User
    Join Date
    Mar 2013
    Location
    London, Ontario, Canada
    Posts
    13
    Quote Originally Posted by DaveHubbard View Post
    I'm not sure, but today it accepts 'using namespace std;', I did notice that I had forgotten to put
    'return 0;'. maybe the program is trying to tell me to look at the program as a whole, and not as individual lines of code.
    Well all I can say is it's time to continue with the Jumping Into C++ e-book. Getting me ready to create a Sudoku 4X4 generating software program.

    Dave
    We should all remember that life is short. For some of us we know this as far too true.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 06-21-2009, 01:13 AM
  2. Can a class know it's being copied?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2008, 03:07 PM
  3. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 03:50 PM
  4. Replies: 3
    Last Post: 03-07-2003, 09:06 PM