0

I'm trying to set up a new dev environment (Cygwin64 on Windows 7) and the following test code is not working:

#include <stdio.h>
#include <string>

int main(int argc, char *argv[])
{
    printf("%s", "Enter main\n\n");
    std::string str;
    printf("%s", "Exit main\n\n");
}

It compiles, but there is no output:

$ g++ test1.cpp

$ ./a.exe

When I comment out the declaration of str, it works fine:

$ ./a.exe

Enter main

Exit main

I must be missing something very simple. The string is never referenced, so declaring it must be exposing some other issue in the code.

The original code was longer and did more operations, but had the same behavior: nothing was printed. I reduced the code to this minimal example. The printfs are just for debugging: please don't respond with an admonition to use cout instead.

EDIT: I spent a few hours on the theory that Avast Anti-Virus might be the culprit. Excluding my code directories didn't help, and neither did disabling Avast. When I scanned a.exe with Avast it was not identified as a threat. Eventually, I copied working and non-working executables to my work computer. On my work computer, nothing was printed to the console by either binary. Both computers are running Windows 7. My home computer is running Avast, but not McAfee. My work computer is running McAfee Anti-Virus, but not Avast. Obviously, something is interfering with executing the binary on my home computer. It doesn't seem to be Avast, but I don't know what it is.

EDIT: the A/V theory seems less plausible now. Somebody suggested that it might be a path issue, such as Cygwin's standard library not being in my path. That sounded very plausible at first:

$ ldd good.exe
    ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x779b0000)
    kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77890000)
    KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefdaa0000)
    cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)

$ ldd bad.exe
    ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x779b0000)
    kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77890000)
    KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefdaa0000)
    cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)
    cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3ffa10000)
    cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x3febb0000)

but it turns out that /usr/bin is right at the beginning of my $PATH.

$ echo $PATH
/cygdrive/d/cygwin64/bin:/usr/local/bin:/usr/bin: (etc.)

When I run under gdb, I get this error:

During startup program exited with code 0xc0000139.

which I believe is failure to load a DLL. When I ran Dependency Walker, it failed to find any of the three Cygwin DLLS it depends on, all of which I can plainly see in /usr/bin.

SOLVED: the cygwin DLLs needed when I declared the std::string (e.g. cygstdc++-6.dll) were not loading, despite being in my path. It turns out that there are known issues when programs compiled with g++ 5.2.x try to load them. I downgraded to g++ 4.9.3, recompiled my code, and it worked right away.

Thanks to everyone who helped.

11
  • 2
    please don't respond with an admonition to use cout instead and then one minute later... @EdHeal Commented Jan 16, 2016 at 20:18
  • 1
    gcc 5.3.0 on linux - works fine Commented Jan 16, 2016 at 20:20
  • 1
    Cannot confirm, runs fine in g++ (Rev3, Built by MSYS2 project) 5.2.0 on Windows 8.1 64bit in PowerShell. Might be something in Cygwin+GCC?
    – Zeta
    Commented Jan 16, 2016 at 20:25
  • 3
    For the second time today - Are you by any chance using Avast antivirus? Running my C++ code gives me a blank console
    – Bo Persson
    Commented Jan 16, 2016 at 20:46
  • 2
    I think it has something to do with cyggcc_s-seh-1.dll when built on cygwin's 64-bit gcc 5.x.x. Try compiling it static and see if that works. (stackoverflow.com/questions/34804384/…) Commented Jan 17, 2016 at 3:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.