g++ - C++ printf no longer works after declaring an std::string -


i'm trying set new dev environment (cygwin64 on windows 7) , following test code 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, there no output:

$ g++ test1.cpp  $ ./a.exe 

when comment out declaration of str, works fine:

$ ./a.exe  enter main  exit main 

i must missing simple. string never referenced, declaring must exposing other issue in code.

the original code longer , did more operations, had same behavior: nothing printed. reduced code minimal example. printfs debugging: please don't respond admonition use cout instead.

edit: spent few hours on theory avast anti-virus might culprit. excluding code directories didn't help, , neither did disabling avast. when scanned a.exe avast not identified threat. eventually, copied working , non-working executables work computer. on work computer, nothing printed console either binary. both computers running windows 7. home computer running avast, not mcafee. work computer running mcafee anti-virus, not avast. obviously, interfering executing binary on home computer. doesn't seem avast, don't know is.

edit: a/v theory seems less plausible now. suggested might path issue, such cygwin's standard library not being in path. sounded plausible @ 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 turns out /usr/bin right @ beginning of $path.

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

when run under gdb, error:

during startup program exited code 0xc0000139. 

which believe failure load dll. when ran dependency walker, failed find of 3 cygwin dlls depends on, of can plainly see in /usr/bin.

solved: cygwin dlls needed when declared std::string (e.g. cygstdc++-6.dll) not loading, despite being in path. turns out there known issues when programs compiled g++ 5.2.x try load them. downgraded g++ 4.9.3, recompiled code, , worked right away.

thanks helped.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -