12

I am trying out Clang (version 3.4, via the Windows pre-built binaries) to see if it could be a suitable replacement for GCC (version 4.8.1, using MinGW); however, I am unable to get a simple program to work.

#include <iostream>

int main()
{
    std::cout << std::endl;
}

Clang is able to compile and link the program, but running it results in a SIGSEGV signal and a return code of 0xC0000005. Outputting a string works fine, but std::flush causes the same result, though allowing the stream to automatically flush itself is okay.

Debugging the program just shows a call stack containing __mingw_CRTStartup() (Clang is using libstdc++, as it didn't install libc++) and std::cout (). What might be causing this, and how could it be fixed?

edit: The same thing happens when using other ostream manipulators such as std::dec and std::unitbuf.

Marco A.
  • 43,032
  • 26
  • 132
  • 246
Kyle
  • 374
  • 1
  • 11
  • 1
    I'd guess that you have a mismatch in standard library versions. How did you install libstdc++ and how are you compiling and linking your executable? – Nate Kohl Mar 06 '14 at 14:52
  • @NateKohl I'm using the version of libstdc++ that was installed by mingw-get alongside the rest of GCC. As for compiling, I am using `clang++ a.cpp` from a command line. – Kyle Mar 20 '14 at 14:06
  • 4
    maybe add "return 0" or replace to "void main()' – Andre Kirpitch Aug 22 '14 at 23:26
  • @Kyle This maybe a stupid suggestion, but make sure that your library paths are pointing to the correct standard library (i.e. the one MinGW installed and not any that already existed previously on your system). To be sure, look up where MinGW drops it libraries and use the -l flag to make sure that's what it's linking against. – NOP Sep 01 '14 at 07:53

1 Answers1

4

There's a bug pending for LLVM 3.4 regarding a similar issue. The problem seems an ABI incompatibility between LLVM 3.4 and MinGW 4.7+ that causes i686 instructions to be picked up instead of the selected target.

A possible solution on x64 Windows is to use a MinGW64 build. That should work but getting the standard library headers right could be tricky.

A recommended solution is to follow the steps here, adjust targets and any path on your system and get it to compile.

Marco A.
  • 43,032
  • 26
  • 132
  • 246