0

I'm trying to make this work with Netbeans+MinGW. It says run failed. I tried to do step by step and came up with this little code:

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv) {
    string input = "";
    return 0;
}

I'm getting RUN FAILED (exit value 57, total time: 364ms). Here I read that not use using namespace std;. I tried that way too, but still run failed. What is the problem? How to use string without run failed?

Community
  • 1
  • 1
adtewa
  • 189
  • 10
  • does it work without `string input = "";` ? – George Jan 27 '17 at 14:12
  • @George Yes, it does. – adtewa Jan 27 '17 at 14:14
  • 3
    This can't normally fail, so you most likely have either your compiler (MinGW) or IDE (NetBeans) setup wrong. Might be incomplete MinGW installation - did you install using the provided installer, or manually from zip archives? E.g. string might be using libraries (locale etc.) which you didn't install properly (missing, wrong version etc.). – EmDroid Jan 27 '17 at 14:15
  • Maybe it's a bug in netbeans? – melpomene Jan 27 '17 at 14:16
  • Do you know if the one failing is the compilation process or the execution of the program itself? Make sure that you are compiling for C++, not for C. – jdehesa Jan 27 '17 at 14:16
  • Cannot reproduce either. The line `string input="";` might be optimized out, but the run should return 0 to environment. Check you Mingw installation. – Serge Ballesta Jan 27 '17 at 14:18
  • Btw. how are you running? From NetBeans in debug mode? (might be that NetBeans doesn't communicate properly with MinGW GDB, at least I always had problems getting that work in Eclipse under Windows). The running time might also point to that, as GDB might try to init the debug sessiion and failed somehow. – EmDroid Jan 27 '17 at 14:19
  • I.e. try to run the compiled program outside of NetBeans on the command line to see if it still fails, then try to run it in command line GDB - then you can diagnose if it is caused by either wrong MinGW installation, or failing GDB, or problem in NetBeans. – EmDroid Jan 27 '17 at 14:23
  • @axalis I used the provided MinGW installer, and I installed everything from the basic setup. – adtewa Jan 27 '17 at 14:26
  • @axalis I ran simply with run project, but now i tried to debug and it said: `During startup program exited with code 0xc0000135.` And I tried to run outside Netbeans and it says `The program can't start because libgcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem.` – adtewa Jan 27 '17 at 14:40
  • 1
    @SimonÁdám you can fix that error with this [link](http://stackoverflow.com/questions/4702732/the-program-cant-start-because-libgcc-s-dw2-1-dll-is-missing) – cuongptnk Jan 27 '17 at 14:55
  • @cuongptnk I've added `-static-libgcc -static-libstdc++` to the compiler options. I did clean and build and it worked outside Netbeans. Then I tried run project in Netbeans, it also worked. Thanks everyone. – adtewa Jan 27 '17 at 15:32
  • Yes, that in general means you are missing some parts of MinGW in the installation (maybe the DLL is not installed by default). Apparently the missing part might be gcc-core--mingw32-dll. – EmDroid Jan 27 '17 at 16:36
  • @axalis I think the problem was that I didn't add the MinGW to PATH. But It's better if a program don't need dependencies like this so my program can work on other computers too. – adtewa Jan 27 '17 at 19:44

1 Answers1

4

In my experience, it would take forever and a waste of time to figure these problems out. A simple solution is trying other IDE. For C++, try Code Block or Visual Studio Express. I did have a lot of weird errors with string library in Code Block, but in Visual Studio it runs well. The problem was that there are some errors in Code Block itself.

cuongptnk
  • 472
  • 3
  • 15
  • 1
    As far as Visual Studio is concerned, you can now even try the new 2017 version which has a completely new compiler flag for improved ISO conformance to replace the old `/Za` flag which never worked right with standard and/or Windows headers. – Christian Hackl Jan 27 '17 at 14:53
  • 1
    Although we found a solution now, I keep your advice and move to Visual Studio, because other problems can occur. And I don't have days to find a solution for every bloomer like this. – adtewa Jan 27 '17 at 15:54