Thread: Anyone gotten Clank to work on Windows?

  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654

    Anyone gotten Clank to work on Windows?

    I am simply trying to compile some code with Clang, but I get problems from the standard library which I borrowed from GCC 4.8.

    I use the command line:

    clang++ "Square Packing.cpp" -I"C:\Program Files\Gecode\include" -I"C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++" -I"C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++\x86_64-w64-mingw32" -I"C:\Program Files\MinGW\x86_64-w64-mingw32\include" -v -std=c++11 -fno-ms-compatibility

    (Clang was built using Visual C++; I have been unable to build it with Mingw.)

    It spits out tons of errors from the standard headers (full log is attached).

    I don't even know if I'm doing this wrong. What friggin' library am I supposed to use, where do I get it and do I set up Clang to work with it?
    It's frustrating that actual instructions on this part seems to be missing!

    If anyone has gotten it working, I'd appreciate some pointers.
    Attached Files Attached Files
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Clang Compiler User’s Manual — Clang 3.3 documentation

    • GCC versions 4.5.0 to 4.5.3, 4.6.0 to 4.6.2, or 4.7.0 (for the C++ header search path)


    Downgrade.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Same error. I think I've tried with 4.6.2, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Strange, that doesn't look like something Clang should have a problem with. I'm currently trying to install GCC 4.8 on my Mac; if I succeed, I can try this out.

    It's all really just one error, occurring multiple times and dragging a host of subsequent errors along.

    C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++\bits/alloc_traits.h:57:35: error: in-class initializer for static data member is not a constant expression
    static const bool __value = _S_chk<_Alloc, _Tp>(nullptr);

    For some reason, it doesn't recognize the constexpr call _S_chk<_Alloc, _Tp>(nullptr) as constant, which causes an error. This error is triggered ultimately from vector's attempt to rebind the allocator you passed to the type you passed (to protect itself from stupid people writing vector<double, allocator<int>>). So allocator_traits<Alloc>::rebind<double>:ther fails to instantiate, and the compiler attempts to recover by making the result int and moving on. But now vector uses 'int' as its allocator type, which causes all sorts of errors when it subsequently attempts to access allocator's various nested types.

    This occurs once for every vector instantiation, and your program includes two, both somewhere in the RNGs that you presumably use (or at least include).

    Edit: Also, I have no idea if this would help this problem, but you will probably have to play with the target triple, if only to get things to link. I believe a VS-built Clang defaults to its incompletely emulated Microsoft ABI, which means all the mangling would be different from the MinGW libstdc++.
    Last edited by CornedBee; 05-05-2013 at 08:02 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, the problem is the chain of includes:

    In file included from Square Packing.cpp:4:
    In file included from ./stdafx.h:8:
    In file included from C:\Program Files\Gecode\include\gecode/int.hh:53:
    In file included from C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++\vector:62:
    In file included from C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++\bits/stl_construct.h:61:
    In file included from C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++\ext/alloc_traits.h:36:
    C:\Program Files\MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++\bits/alloc_traits.h:57:35: error: in-class initializer for static data member is not a constant expression

    It's not even in my code. It's just headers it's trying to include. Apparently some header is trying to create a vector of doubles which causes this cascade error. So something is wrong with the library, or the compiler can't handle it.
    But I noticed it won't even compile with g++, so maybe my installation is broken. I'm going to try wiping it and reinstalling.

    EDIT:
    Got a new distro from here: MinGW Distro - nuwen.net (32bit)
    Now compiles with GCC (but does not link), but still no luck with Clank. New error report attached.

    EDIT2:
    Regarding ABI, I have absolutely no idea how to change that. There is no good guide on how to compile or build Clang.
    Attached Files Attached Files
    Last edited by Elysia; 05-05-2013 at 08:33 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Sorry, can't reproduce on my computer. My Clang is some pre-3.3 custom build, but that shouldn't really make a difference.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If there's anything I've learned, it's that there apparently exists many libstdc++ libraries versions and types. I don't know which one Clang wants. I've gotten two different results with two different mingw distros, but same GCC version...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    I followed the guide here: c++ - How to compile Clang on Windows - Stack Overflow

    I also made sure to download the following version of MinGW: http://downloads.sourceforge.net/pro...ror=netcologne

    I also used prepackaged repository catalogues. Make sure you select C++ compiler and the MinGW developer toolkit. This gave me gcc 4.6.2 with everything needed. Also add the bin folder to your path (default is C:\MinGW\bin).

    Was able to compile Clang 3.2 with this and a simple hello world application seems to work at least.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I haven't tried compiling it myself yet, but I managed to get it to work with (from the first you link you posted, thanks!):

    https://sourceforge.net/projects/min...g-3.2-release/ (i686-w64-mingw32-clang-3.2-release-win32_rubenvb.7z)
    and
    https://sourceforge.net/projects/min...2-4.6-release/ (i686-w64-mingw32-gcc-dw2-4.6.3-2-release-win32_rubenvb.7z)

    Note: Both are unpacked to the same directory.
    I would like to get it to work with GCC 4.8 since apparently that's what is required to support thread_local. More tests are required, but I'm happy with getting it to work in the first place.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Update:
    I managed to make Clang compile.
    Solutions:
    - Don't use anything higher than GCC 4.6.3. It won't compile. Period.
    - Using Visual Studio to compile Clang if you are intending to use the Mingw headers is a bad idea. I managed to get it to work by defining these defines, though:

    -D__MSVCRT__
    -D_X86_
    -D__i386__
    -Di386
    -DWIN32
    -D_AMD64_
    -D__declspec(a)=__attribute__((a))

    Also, disable MS compatibility by these flags:

    -fno-ms-compatibility
    -fmsc-version=0

    Don't forget that you will need to include the mingw header paths:

    -I"C:\test\mingw32-dw2-4.6.3\include\c++\4.6.3"
    -I"C:\test\mingw32-dw2-4.6.3\include\c++\4.6.3\i686-w64-mingw32"
    -I"C:\test\mingw32-dw2-4.6.3\i686-w64-mingw32\include"

    Finally, this may or may not a be a problem, but Clang defines an x86intrin.h header, while some other distributions (like MS) defines intrin.h. I had to make a symlink (or rename) x86intrin.h to intrin.h to make certain code compile.

    Now onto the linker problems...
    Last edited by Elysia; 05-10-2013 at 05:57 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I suppose I should update what more progress I have.
    I have managed to get clang to compile with mingw. Here is a nice script that I use to build it:

    @echo off
    echo Updating llvm...
    svn up .
    echo Updating clang...
    svn up tools/clang
    echo Configuring llvm and clang...
    cd build_mingw
    path=%path%;"C:\test\mingw64-4.8\bin"
    cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..
    echo Compiling llvm and clang...
    start /low /affinity 7f /wait /b mingw32-make -j 7
    echo Copying clang executables to mingw directory...
    copy bin\*.* C:\test\mingw32-dw2-4.6.3\bin /y
    echo Done!

    This assumes you have mingw installed (I used v4.8) (script assumes path "C:\test\mingw64-4.8\bin" and adds it to path; you can remove that if mingw is already in path).
    You will need to do have downloaded clang and llvm via svn as described on their homepage. Change affinity and -j <threads> as appropriate for your system (affinity is a hexadecimal representation for which cores you want the process to use; I always disable one core to ensure it doesn't stall the system).
    Building clang with mingw makes it work out of box with mingw headers, even 4.8. Still can't get thread_local to work even though the homepage says it should work with 4.8.
    Unfortunately, clang won't link with the 4.8 linker. The latest version I had success with is 4.6.3, so that's why I copy the files there.
    It also seems that clang doesn't have built-in paths for 4.8 (only up to 4.7), so you're going to have to manually specify the include paths to clang, just like above.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't get MCAST_JOIN_GROUP to work on Windows 7
    By Clairvoyant1332 in forum Windows Programming
    Replies: 1
    Last Post: 03-18-2013, 06:33 AM
  2. Does \n work on Windows?
    By Programmer_P in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2010, 12:32 PM
  3. compiled under windows, work for mac os?
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2002, 09:55 AM
  4. Getting Layered Windows to Work
    By Si in forum Windows Programming
    Replies: 3
    Last Post: 01-22-2002, 06:21 PM
  5. Replies: 6
    Last Post: 01-07-2002, 02:46 AM