News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

C::B won't build my C++ file

Started by iamunited, January 28, 2010, 02:32:07 AM

Previous topic - Next topic

iamunited

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:


#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

TerryP

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

MortenMacFly

Quote from: iamunited 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.
[...]
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

iamunited

Where can I go to install the C++ Compiler?

MortenMacFly

Quote from: iamunited on January 28, 2010, 07:30: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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

MortenMacFly

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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

iamunited


stahta01

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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

iamunited


MortenMacFly

Quote from: iamunited on January 28, 2010, 06:46:42 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

iamunited

#10
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:

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


Here are the errors:

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 ===|



stahta01

TURN ON FULL LOGGING

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

iamunited

Quote from: stahta01 on January 29, 2010, 04:22:30 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.

Jenna

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.

MortenMacFly

Quote from: jens 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++ !!!
Quote from: MortenMacFly on January 28, 2010, 08:05:31 PM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]