Author Topic: C::B won't build my C++ file  (Read 16822 times)

Offline iamunited

  • Single posting newcomer
  • *
  • Posts: 8
C::B won't build my C++ file
« on: January 28, 2010, 02:32:07 am »
I have been using C::B for awile but used it in C. But I would rather use C++ but I cannot get it to build my file.

Here is what I am trying to run, very simple program:

Code
#include <iostream>
using namespace std;
int main()
{
    cout << "I have installed putty" << endl;
}

I know this says that this is not a programming forum but I need help getting C::B to work properly. Worked fine for C.

Thanks

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: C::B won't build my C++ file
« Reply #1 on: January 28, 2010, 06:04:17 am »
That is a valid enough C++ program.

You might get more help by specifying....

0.) Code::Blocks version
1.) Compiler/version
2.) The exact error message from Code::Blocks


if it fails to compile, I would expect your compiler or project settings are flubbed.
Just Another Computer Geek

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B won't build my C++ file
« Reply #2 on: January 28, 2010, 07:00:14 am »
I have been using C::B for awile but used it in C. But I would rather use C++ but I cannot get it to build my file.
[...]
Worked fine for C.
Make sure you installed the C++ compiler, too. This is a separate package.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline iamunited

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B won't build my C++ file
« Reply #3 on: January 28, 2010, 07:30:00 am »
Where can I go to install the C++ Compiler?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B won't build my C++ file
« Reply #4 on: January 28, 2010, 08:00:00 am »
Where can I go to install the C++ Compiler?
Depends on your system/config which you still did not tell.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B won't build my C++ file
« Reply #5 on: January 28, 2010, 08:01:10 am »
You can also first verify if g++ is installed by typing g++ on the command line and see what happens (assuming you are on Linux).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline iamunited

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B won't build my C++ file
« Reply #6 on: January 28, 2010, 05:44:49 pm »
Windows 7 32 bit

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B won't build my C++ file
« Reply #7 on: January 28, 2010, 06:01:25 pm »
Try

Logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"

Is it using gcc or g++ to compile?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline iamunited

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B won't build my C++ file
« Reply #8 on: January 28, 2010, 06:46:42 pm »
It's using GNU GCC Compiler.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B won't build my C++ file
« Reply #9 on: January 28, 2010, 08:05:31 pm »
It's using GNU GCC Compiler.
Could it be that you are trying to compile a C++ application with a file extension *.c? This won't work. You cannot compile C++ code with a C compiler. You'll either need to comply with the standard and use e.g. *.cpp as file extension for C++ or you'll need to set the compiler variable for this very file in the file properties explicitly. The latter is not very convenient.

nevertheless, I am still missing a lot important information:
- What C::b version,
- what compiler version,
- what's the EXACT full compiler log?

If you don't want to provide enough information I can't (and won't) help you.

Look: You are basically asking "My code doesn't compile". this can have 1 million reasons, e.g. missing access rights, too. To tell we need more information.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline iamunited

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B won't build my C++ file
« Reply #10 on: January 29, 2010, 02:08:03 am »
Code
nevertheless, I am still missing a lot important information:
- What C::b version,
- what compiler version,
- what's the EXACT full compiler log?

1) What C::B Version?
            I have version 8.02 MinGW
2) What Compiler Version
            I am not sure what Compiler Version I have, where do I find that I will tell you it.

3) What's the EXACT full Compiler Log
            I am going to assume this is what your asking for.

            GNU GCC Compiler
            Microsoft Visual C++ Toolkit 2003
            Microsoft Visual C++ 2005/2008
            Borland C++ Compiler (5.5, 5.82)
            Digital Mars Compiler
            OpenWatcom (W32) Compiler
            GNU GCC Compiler for MSP430
            Cygwin GCC
            Intel C/C++ Compiler
            SDCC Compiler
            Tiny C Compiler
            GDC D Compiler
            Digital Mars D Compiler
            GNU ARM GCC Compiler
            GNU AVR GCC Compiler
            GNU GCC Compiler for PowerPC
            GNU GCC Compiler for Tricore

It finally tried to build and run

Here is the latest action.....Errors everywhere but not sure why

My Code:
Code
#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World" << endl;
}

Here are the errors:
Code
C:\Users\Brent\Desktop\Untitled1.c|1|iostream: No such file or directory|

C:\Users\Brent\Desktop\Untitled1.c|2|error: syntax error before "namespace"|

C:\Users\Brent\Desktop\Untitled1.c|2|error: ISO C forbids data
definition with no type or storage class|

C:\Users\Brent\Desktop\Untitled1.c||In function `main':|

C:\Users\Brent\Desktop\Untitled1.c|5|error: `cout' undeclared (first use in this function)|

C:\Users\Brent\Desktop\Untitled1.c|5|error: (Each undeclared identifier is reported only once|

C:\Users\Brent\Desktop\Untitled1.c|5|error: for each function it appears in.)|

C:\Users\Brent\Desktop\Untitled1.c|5|error: `endl' undeclared (first use in this function)|

||=== Build finished: 7 errors, 0 warnings ===|

« Last Edit: January 29, 2010, 04:01:14 am by iamunited »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B won't build my C++ file
« Reply #11 on: January 29, 2010, 04:22:30 am »
TURN ON FULL LOGGING

Logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline iamunited

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B won't build my C++ file
« Reply #12 on: January 29, 2010, 05:31:00 am »
TURN ON FULL LOGGING

Logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"


Full Logging has been turned on since your first post telling me to.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: C::B won't build my C++ file
« Reply #13 on: January 29, 2010, 07:00:24 am »
Your sourc-file is named Untitled1.c, C::B treats is a C-file not as C++ !!!
That can not work, make sure the file-ending is cpp if you create a C++ file.

You can also force C::B to use g++ instead of gcc, but this is more difficult and hackky and might lead to later errors.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B won't build my C++ file
« Reply #14 on: January 29, 2010, 07:08:25 am »
Your sourc-file is named Untitled1.c, C::B treats is a C-file not as C++ !!!
Could it be that you are trying to compile a C++ application with a file extension *.c? This won't work.
How often do you want to be advised? Please react accordingly.

Topic locked so we don't waste more time here.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ