Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang on Cygwin with C++11

I installed Clang on Cygwin and I try to compile this code:

#include <iostream>
int main() {
  std::cout << "hello world!" << std::endl;
  return 0;
}

That works fine if I do clang++ file.cpp. It does not work if I do clang++ file.cpp -std=c++11. I get errors from standard headers like this:

In file included from file.cpp:1:
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/iostream:39:
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/ostream:39:
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/ios:39:
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/exception:150:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/exception_ptr.h:132:13: error:
      unknown type name 'type_info'
      const type_info*

Does Cygwin Clang just not work with C++11 turned on, or is there something I can do to get around this?

like image 213
Bjarke H. Roune Avatar asked Oct 17 '12 16:10

Bjarke H. Roune


2 Answers

It looks like a bug in the standard library. exception_ptr.h is only included in C++11 mode, which is why you don't see it otherwise. The problem is, exactly as the error says, that std::type_info is not declared. It seems GCC magically forward declares certain names in the std namespace which is why it is unaffected! You can prove it yourself with a simple program:

namespace std {  

    class A
    {
    public:
         type_info* B();
    };
}

This compiles with GCC 4.5.3 but Clang gives an error no matter what the -std setting.

The problem is fixed in the latest version of GCC so manually updating is probably your best bet. The 4.7.2 release configured with --enable-languages=c,c++ compiles no problem under Cygwin.

like image 160
John Richardson Avatar answered Oct 05 '22 23:10

John Richardson


It is possible and relatively easy to get the Clang package working on Cygwin with C++11.

The error you are describing, for example, is fixed by adding

#ifdef __clang__
    class type_info;
#endif

to exception_ptr.h. Another error which needs to be fixed is to add a copy constructor to std::pair.

This is unfortunate, though, and hopefully the Cyginw gcc packages will be updated to a newer version of the C++ standard library.

like image 44
Petter Avatar answered Oct 05 '22 23:10

Petter