Codeblocks won't run executable - c++

somehow codeblocks decided not to run any new programs anymore. All I get is a black screen when running. Take for example the simple "Hello World" program. That will not even run. It compiles just fine without any error. All i see though when codeblocks opens is a black screen.
I tried looking online for help. It looked like this
Can't find file executable in your configured search path for gnc gcc compiler
would fix the problem. It didn't though.
This was my code:
#include <iostream>
using namespace std;
int main(){
cout<< "Hello World!" << endl;
return 0;
}
I don't know what happened and why. Sincerely hoping for an answer.

Related

C++ "Hello world" shows no output

I installed Codeblocks on my Windows 10 computer. To check that everything works fine, I first compiled the simple C program
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
That works without problem but when I try the C++ equivalent:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return(0);
}
Then the "command prompt" window opens but no output is shown. I can see in taskmanager that the program is running but as said without any visible output. I also tried running the program directly from the command line but with the same effect. Anyone any ideas?
I found the issue. There was still an older version of MinGW installed in a different folder. I deleted all instances of MinGW, and codeblocks as well. Adter I reinstalled codeblocks everything worked as it should.
This Guy solved similar problem with Codeblocks.
Remove the following Global compiler setting:
-Wl,-subsystem,windows

iostream alone gives me 457 errors

I'm new to both C++ and Visual Studio 2015 and already have 457 errors in my first program.
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
this simple piece of "hello world" code gave me 457 errors so I started experimenting and found out that even this
#include <iostream>
by itself gives me all those errors. I have no idea how to fix this.
Your hello world program is correct. See here
What you may want to look into is if PATH environment variable on your Windows Machine is set correctly.
Alternatively, you may want to compile the program in Windows shell/powershell and see if that is working for you.
May I also recommend using mingw installer and get started right away with your compilation & execution.

No output in c++-program if object is instantiated using Eclipse

I got an issue after installing Eclipse Kepler on my Windows 7 32bit machine. I installed the CDT and the MinGW-compiler. I configured the installation by adding MinGW to the PATH and tested my configuration with a "Hello world"-program, which worked.
The strange thing is, that if I instantiate an object, nothing is outputted. It doesn't matter if it's a std::string or a custom made class. If I instantiate it, nothing is outputted, even if it should be outputted before the instantiation. The exact same code works fine, if I compile it with cygwin gcc from command line. If I change the toolchain to cygwin gcc nothing changes (I've rebuild the program with "build all").
There is no error displayed and no problem listed.
Here's the minimal working example:
#include <iostream>
#include <string>
using namespace std;
class SayWorld{
public:
SayWorld(){
cout << "World!" << endl;
}
};
int main() {
//Only gets outputted, if the lines, that don't work are commented out:
cout << "Hello ";
// Works:
cout << "World!" << endl;
// Doesn't work:
// SayWorld sw;
// Also doesn't work:
// string str("World!");
// cout << str << endl;
return 0;
}
Edit 2:
I narrowed the error to MinGW, as this picture of a Cygwin-Bash-Terminal demonstrates. (The file was not changed beetween the to g++ calls and contains the example above)
Edit 1 (Legacy)
Toolchain-picture:
-picture removed- (don't think it was necessary)
After reinstalling eclipse and MinGW again, step-by-step following this video tutorial:
http://www.youtube.com/watch?v=77xZOT3xer4
and having the same problem afterwards, I stumbled uppon this post in the eclipse forum:
http://www.eclipse.org/forums/index.php/u/104305/
which has brought me to this solution:
Right-click Project -> Properties -> Run/Debug Settings
Choose executable and hit the "New"-button.
Go to the Environment-Tab and create a new variable named PATH with the value: "C:\MinGW\bin".
As I am no expert, I can't explain to you why it works, but it worked for me. If someone knows, how to do this better or wholly avoid this problem, I'd be glad to listen.
This entry was definitively in my Windows-PATH...
PS.: The problem seems also to be known here:
unable to see the output of c++ program in the console

Codeblocks outputs broken executable

I have downloaded plenty of different versions of code blocks, and none of them compiles quite right. My hello world runs within code blocks just fine. However, when I run the executable outside of codeblocks, it says "Hello.exe has stopped working". There isn't anything wrong with my code (I don't think.) and my mingw compiles fine outside of codeblocks. What does codeblocks do to my executable? Is there some option to fix this? I am on windows 7 64 bit, and my current code blocks version is 10.05. My program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
cin.ignore();
return 0;
}
I solved the problem. I had a broken compiler (or something like that). My suggestion for other people with this problem is to experiment with different versions of the minGW compiler. Also, change the version of code blocks you are using, or even uninstall everything and restart. The problem with mine was I downloaded a bad compiler. [The truth is, codeblocks isn't the best ide.]

mingw produces broken .exe

I have installed the newest MinGW suite. My project still compiles without any error but the produced executable is not working. Starting it results in the well known windows xp error message. Paradoxically source code like
#include <stdio.h>
int main()
{
printf("test\n");
return 0;
}
produces a working executable while
#include <iostream>
int main()
{
std::cout << "test\n" << std::endl;
return 0;
}
compiles fine but the executable is broken as described above.
Before i made the update everything worked. So what goes wrong here?
Do you have the libstdc++-*.dll in the path? It may be shared in newer MinGW versions, and std::cout uses it.
A tool like Process Monitor will probably tell you what is actually going wrong in more detail, and possibly even tell you what you need to fix to make it work.