get clang to use gcc headers instead of Visual Studio headers

Hello,

I would like to try out clang++, to see how suitable of a substitute
it might be for g++ as a cross-platform C++ compiler.

I've built clang on Windows using the instructions provided here for
Visual Studio: http://clang.llvm.org/get_started.html,
and now I'm trying to get it to compile a project that was previously
compiled with MinGW's g++.

However, I get a bunch of errors, and in the errors I can see that
clang++ is using the system headers provided by Visual Studio.

Is there a way to get clang++ to use the MinGW g++ headers instead?

Thanks,
Nate.

The -nostdinc flag will turn off Clang's default includes; then you can use -I flags to point Clang at the right include paths for MinGW.

  - Doug

Hi Doug,

That worked, but now when I try to compile a test file that simply
includes , I get the following errors:

[snip]

Probably nothing. It's likely that there is a configuration issue with
Clang on mingw, since very, very few people have tried to make this
configuration work.

All right, so I tried compiling a test file that includes < string>
using the default Visual Studio headers. I'm assuming that
clang and Visual Studio headers *is* a common configuration (if not,
then what is?), so what am I doing wrong this time?

Here are the errors:

In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:6:
In file included from c:\Dev\Programs\MSVS\VC\include/exception:40:
c:\Dev\Programs\MSVS\VC\include/eh.h(61) : error: unknown type name 'type_info'
_CRTIMP int __cdecl _is_exception_typeof(_In_ const type_info &_Type, _In_ struct ...
                                                    ^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:8:
c:\Dev\Programs\MSVS\VC\include/new(53) : error: exception specification in declaration does not
      match previous declaration
_Ret_bytecap_(_Size) void *__CRTDECL operator new(size_t _Size) _THROW1(std::bad_alloc);
                                     ^
note: previous declaration is here
c:\Dev\Programs\MSVS\VC\include/new(81) : error: exception specification in declaration does not
      match previous declaration
_Ret_bytecap_(_Size) void *__CRTDECL operator new(size_t _Size)
                                     ^
note: previous declaration is here
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:9:
In file included from c:\Dev\Programs\MSVS\VC\include/xutility:7:
In file included from c:\Dev\Programs\MSVS\VC\include/utility:6:
In file included from c:\Dev\Programs\MSVS\VC\include/iosfwd:8:
In file included from c:\Dev\Programs\MSVS\VC\include/cwchar:13:
c:\Dev\Programs\MSVS\VC\include/wchar.h(1209) : error: expected expression
        {return (_P == NULL || *_P == 0); }
                            ^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:9:
In file included from c:\Dev\Programs\MSVS\VC\include/xutility:7:
In file included from c:\Dev\Programs\MSVS\VC\include/utility:6:
c:\Dev\Programs\MSVS\VC\include/iosfwd(219) : error: no member named '_invalid_parameter_noinfo' in
      the global namespace; did you mean '_invalid_parameter_handler'?
                _SCL_SECURE_CRT_VALIDATE(_Dest_size>= _Count, NULL);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:6:
In file included from c:\Dev\Programs\MSVS\VC\include/climits:5:
c:\Dev\Programs\MSVS\VC\include/yvals.h:226:4: note: instantiated from:
                        _SCL_SECURE_INVALID_PARAMETER(cond); \
                        ^
c:\Dev\Programs\MSVS\VC\include/yvals.h:183:47: note: instantiated from:
#define _SCL_SECURE_INVALID_PARAMETER(expr) ::_invalid_parameter_noinfo()
                                            ~~^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:9:
In file included from c:\Dev\Programs\MSVS\VC\include/xutility:7:
In file included from c:\Dev\Programs\MSVS\VC\include/utility:6:
c:\Dev\Programs\MSVS\VC\include/iosfwd(219) : error: expected expression
                _SCL_SECURE_CRT_VALIDATE(_Dest_size>= _Count, NULL);
                ^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:6:
In file included from c:\Dev\Programs\MSVS\VC\include/climits:5:
c:\Dev\Programs\MSVS\VC\include/yvals.h:227:20: note: instantiated from:
                        return (retvalue); \
                                        ^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:9:
In file included from c:\Dev\Programs\MSVS\VC\include/xutility:7:
In file included from c:\Dev\Programs\MSVS\VC\include/utility:6:
c:\Dev\Programs\MSVS\VC\include/iosfwd(249) : error: no member named '_invalid_parameter_noinfo' in
      the global namespace; did you mean '_invalid_parameter_handler'?
                _SCL_SECURE_CRT_VALIDATE(_Dest_size>= _Count, NULL);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:6:
In file included from c:\Dev\Programs\MSVS\VC\include/climits:5:
c:\Dev\Programs\MSVS\VC\include/yvals.h:226:4: note: instantiated from:
                        _SCL_SECURE_INVALID_PARAMETER(cond); \
                        ^
c:\Dev\Programs\MSVS\VC\include/yvals.h:183:47: note: instantiated from:
#define _SCL_SECURE_INVALID_PARAMETER(expr) ::_invalid_parameter_noinfo()
                                            ~~^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:9:
In file included from c:\Dev\Programs\MSVS\VC\include/xutility:7:
In file included from c:\Dev\Programs\MSVS\VC\include/utility:6:
c:\Dev\Programs\MSVS\VC\include/iosfwd(249) : error: expected expression
                _SCL_SECURE_CRT_VALIDATE(_Dest_size>= _Count, NULL);
                ^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:6:
In file included from c:\Dev\Programs\MSVS\VC\include/climits:5:
c:\Dev\Programs\MSVS\VC\include/yvals.h:227:20: note: instantiated from:
                        return (retvalue); \
                                        ^
In file included from test.cpp:1:
In file included from c:\Dev\Programs\MSVS\VC\include/string:6:
In file included from c:\Dev\Programs\MSVS\VC\include/istream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ostream:6:
In file included from c:\Dev\Programs\MSVS\VC\include/ios:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocnum:9:
In file included from c:\Dev\Programs\MSVS\VC\include/streambuf:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xiosbase:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xlocale:8:
In file included from c:\Dev\Programs\MSVS\VC\include/stdexcept:7:
In file included from c:\Dev\Programs\MSVS\VC\include/xstring:6:
In file included from c:\Dev\Programs\MSVS\VC\include/xmemory:9:
c:\Dev\Programs\MSVS\VC\include/xutility(995) : error: template argument for template type
      parameter must be a type
                iterator_traits<_Iter1>::iterator_category,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c:\Dev\Programs\MSVS\VC\include/xutility(960) : note: template parameter is declared here
template<class _Cat1, class _Cat2>
               ^
c:\Dev\Programs\MSVS\VC\include/xutility(996) : error: expected a qualified name after 'typename'
                iterator_traits<_Iter2>::iterator_category>::_Iter_random_cat _Cat;
                                                             ^
c:\Dev\Programs\MSVS\VC\include/xutility(996) : error: no template named '_Iter_random_cat'; did
      you mean '_Iter_random'?
                iterator_traits<_Iter2>::iterator_category>::_Iter_random_cat _Cat;
                                                             ^~~~~~~~~~~~~~~~
                                                             _Iter_random
c:\Dev\Programs\MSVS\VC\include/xutility(996) : error: unknown type name '_Iter_random_cat'
c:\Dev\Programs\MSVS\VC\include/xutility(1008) : error: template argument for template type
      parameter must be a type
                iterator_traits<_Iter1>::iterator_category,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c:\Dev\Programs\MSVS\VC\include/xutility(974) : note: template parameter is declared here
template<class _Cat1, class _Cat2, class _Cat3>
               ^
c:\Dev\Programs\MSVS\VC\include/xutility(1010) : error: expected a qualified name after 'typename'
                iterator_traits<_Iter3>::iterator_category>::_Iter_random_cat _Cat;
                                                             ^
c:\Dev\Programs\MSVS\VC\include/xutility(1010) : error: no template named '_Iter_random_cat'; did
      you mean '_Iter_random'?
                iterator_traits<_Iter3>::iterator_category>::_Iter_random_cat _Cat;
                                                             ^~~~~~~~~~~~~~~~
                                                             _Iter_random
c:\Dev\Programs\MSVS\VC\include/xutility(1010) : error: unknown type name '_Iter_random_cat'
c:\Dev\Programs\MSVS\VC\include/xutility(1065) : error: expected expression
                typedef typename _Checked_iterator_category_helper<_Iter, _...
                                                                          ^
c:\Dev\Programs\MSVS\VC\include/xutility(1065) : error: definition or redeclaration of
      '_Checked_cat' cannot name the global scope
  ...__is_base_of(_Iterator_base_universal, _Iter)>::_Checked_cat _Checked_cat;
                                                   ~~^
c:\Dev\Programs\MSVS\VC\include/xutility(1065) : error: typedef declarator cannot be qualified
  ...__is_base_of(_Iterator_base_universal, _Iter)>::_Checked_cat _Checked_cat;
                                                   ~~^
fatal error: too many errors emitted, stopping now
20 errors generated.

Thanks,
Nate.

There are no common configurations of clang on Windows; the primary
developers use OS X, and most of the rest use either Linux or FreeBSD.

You're not doing anything wrong; the issue is just that nobody has
done the work to make the MSVC C++ headers work with clang.

-Eli

That worked, but now when I try to compile a test file that simply
includes , I get the following errors:

[snip]

Probably nothing. It's likely that there is a configuration issue with
Clang on mingw, since very, very few people have tried to make this
configuration work.

All right, so I tried compiling a test file that includes < string>
using the default Visual Studio headers. I'm assuming that
clang and Visual Studio headers *is* a common configuration (if not,
then what is?), so what am I doing wrong this time?

There are no common configurations of clang on Windows; the primary
developers use OS X, and most of the rest use either Linux or FreeBSD.

So you cannot use it on Windows at all? If so, why has someone taken
the trouble to put together instructions to build it on Windows
in the first place?

Thanks,
Nate.

Making Clang work on Windows is an all-volunteer effort. Some things work, and some things don't, and I'm sure those who have been working on Clang for Windows would appreciate help.

  - Doug

So you cannot use it on Windows at all? If so, why has someone taken
the trouble to put together instructions to build it on Windows
in the first place?

Well given that Windows != Visual Studio.... :slight_smile:

(Sorry, Seemed I replied only to Anton only by acident.)

I’d recommend installing the TDM version of MinGW and putting it in your path (make sure that the gcc/g++ exe’s are named gcc.exe and g++.exe) and point clang at the MinGW headers. You’ll have significantly less issues.

I can say that regarding C only , Clang signals errors only for following VS 2010 standard headers

#include <complex.h>
#include <fenv.h>
#include <inttypes.h>
#include <tgmath.h>

when using : clang -cc1 -fms-extensions -C test/t.c