Trying again - building 64bit code on Windows

Is clang built form the latest svn source capable of creating 64-bit code on a Microsoft Windows 64-bit OS ? If yes, is this done through the -m64 option or do I have to build clang from source in some particular way to enable the functionality ?

I searched clang, Windows, and 64-bit code and have come up with just about nothing. Furthermore in the clang user's guide the only mention that I can see is:

"X86

The support for X86 (both 32-bit and 64-bit) is considered stable on Darwin (Mac OS X), Linux, FreeBSD, and Dragonfly BSD: it has been tested to correctly compile many large C, C++, Objective-C, and Objective-C++ codebases."

That does not explain much so I am hoping some clang developer can explain more to me. OTOH if I get the silent treatment again I will just assume that compiling 64-bit code with clang on a Microsoft Windows 64-bit OS is not a reality and won't bother pursuing it further other than tell other interested Boost developers that it can't be done. Thanks !

OTOH if I get the silent treatment again I will just assume that
compiling 64-bit code with clang on a Microsoft Windows 64-bit OS is
not a reality and won't bother pursuing it further other than tell
other interested Boost developers that it can't be done. Thanks !

You shouldn't state things as fact that you don't know to be true. If you're going to say anything to the Boost devs w.r.t. this, be honest with them, and tell them that you don't know how to do it or whether it is even possible. Nobody benefits from such misinformation.

Just in case anyone else might want to know…

I don’t think this is a clang/llvm or boost issue. It’s more of a cmake/ninja issue, and it works fine. (although I no longer use windows and didn’t try to test it).

This should help:

http://stackoverflow.com/questions/31262342/cmake-g-ninja-on-windows-specify-x64

You could also look at the build bots – they seem to build 64bit windows without too much difficulty…

Is clang built form the latest svn source capable of creating 64-bit code on
a Microsoft Windows 64-bit OS ?

Yes. We build 64-bit Chromium on Windows with Clang continuously.

If yes, is this done through the -m64 option
or do I have to build clang from source in some particular way to enable the
functionality ?

Yes, using clang-cl -m64 is how we do it.

Cheers,
Hans

You are right. I will let Boost developers worry about any problems they encounter with clang themselves.

Just in case anyone else might want to know...

I don't think this is a clang/llvm or boost issue. It's more of a
cmake/ninja issue, and it works fine. (although I no longer use windows
and didn't try to test it).

This should help:

http://stackoverflow.com/questions/31262342/cmake-g-ninja-on-windows-specify-x64

I have already been told previously that the mingw(-64)/gcc toolchain used to build clang is independent of the mingw(-64)/gcc toolchain used as the RTL when clang itself is used to compile/link. Your link implies that I have to build clang using a 64-bit version of mingw-64/gcc in order to compile/link 64-bit code using clang. Is that true ?

>

You could also look at the build bots -- they seem to build 64bit
windows without too much difficulty...

What are the "build bots" and how do I "look" at them ?

Is clang built form the latest svn source capable of creating 64-bit code on
a Microsoft Windows 64-bit OS ?

Yes. We build 64-bit Chromium on Windows with Clang continuously.

I am building for a mingw-64/gcc target. Do I need to build using a 64-bit version of mingw-64/gcc in order to have clang be able to create 64-bit code ?

If yes, is this done through the -m64 option
or do I have to build clang from source in some particular way to enable the
functionality ?

Yes, using clang-cl -m64 is how we do it.

Does this work as:

clang -m64 when targeting mingw(-64)/gcc ?

Just in case anyone else might want to know...

I don't think this is a clang/llvm or boost issue. It's more of a
cmake/ninja issue, and it works fine. (although I no longer use windows
and didn't try to test it).

This should help:

http://stackoverflow.com/questions/31262342/cmake-g-ninja-on-windows-specify-x64

I have already been told previously that the mingw(-64)/gcc toolchain used
to build clang is independent of the mingw(-64)/gcc toolchain used as the
RTL when clang itself is used to compile/link. Your link implies that I
have to build clang using a 64-bit version of mingw-64/gcc in order to
compile/link 64-bit code using clang. Is that true ?

Didn't mean to imply anything. Hans's answer is best.

>

You could also look at the build bots -- they seem to build 64bit
windows without too much difficulty...

What are the "build bots" and how do I "look" at them ?

Continuous builds...

http://lab.llvm.org:8011

hth...
don

You are a funny chap, http://bfy.tw/1SV5

Evidently to build a version of clang on Windows targeting mingw-64/gcc, which can compile 64-bit code, one must build clang with a 64-bit version of mingw-64/gcc. This may be apparent to you and other clang developers but it was not apparent to me.

I would like to add to the documentation on the clang "Getting Started: Building and Running Clang" page at http://clang.llvm.org/get_started.html a section of documentation following the section "Using Visual Studio" called "Using mingw(-64)/gcc". This section would explain how to build clang on Windows using ninja, CMake, and a mingw(-64)/gcc implementation and how to run clang from the command line using a mingw(-64)/gcc RTL. I am willing to completely write this documentation, to be vetted by whatever clang developer takes care of that "Getting Started" page, in order to help other developers build and run clang on Windows with the mingw(-64)/gcc RTL.

Evidently to build a version of clang on Windows targeting mingw-64/gcc, which can compile 64-bit code, one must build clang with a 64-bit version of mingw-64/gcc. This may be apparent to you and other clang developers but it was not apparent to me.

clang may be built with any supported regardless the target. For example, I’m building clang using Visual C++ 64 bit and targetting the 32-bit version of mingw. You do need to have the target mingw installed for the include files, library files and linker.

If i understand you correctly (english is not my native language), you are
saying that Clang must be a 64bit app, to be able to produce 64bit apps?

Where did you get that? I have a 32bit Clang here (built with 32bit mingw)
which is perfectly capable of producing 64bit apps. I just tried it,
targeting both Mingw and MSVC.

Heres the command line i used:
$ clang++ test2.cpp -static -m64 --sysroot=/c/Dev/Mingw64/

You have to put the mingw64bit/bin folder in the PATH. I did this before i
ran the command:
$ export PATH="/c/Dev/Mingw64/bin/:PATH"

After i did this, both Mingws were on the PATH, but the 64bit comes first,
otherwise Clang would run the 32bit linker.

That is not my experience.

I build a 32-bit version of clang using mingw-64/gcc-5.1 32-bit. Before executing clang I add both the clang 32-bit 'bin' directory and a mingw-64/gcc-5.1 64-bit 'bin' directory to the front of my Windows PATh. I then open a command window and execute:

clang++ --version

The response is a Windows message saying:

"The program can't start because libgcc_s_dw2-1.dll is missing from your computer."

If I try:

clang++ --version -m64

I get the exact same Windows message.

So clearly my experience shows me that if I build a version of clang using a 32-bit version of mingw-64 I can not then execute clang++ if it picks up a 64-bit version of mingw-64 first in the PATH.

In the same situation with a 64-bit version of clang built using mingw-64/gcc-5.1 64-bit there is no problem when I execute

clang++ --version

I get back:

clang version 3.8.0 (trunk 245568)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\Programming\VersionControl\bninja_installed_clang_64\bin

Evidently to build a version of clang on Windows targeting mingw-64/gcc, which can compile 64-bit code, one must build clang with a 64-bit version of mingw-64/gcc. This may be apparent to you and other clang developers but it was not apparent to me.

clang may be built with any supported regardless the target. For
example, I'm building clang using Visual C++ 64 bit and targetting the
32-bit version of mingw. You do need to have the target mingw installed
for the include files, library files and linker.

Please see my other response in this thread to Ivan. My experience is clearly that a 32-bit version of clang does not work when a 64-bit version of mingw-64/gcc is first in the Windows PATH. I also explained this previously in my post "Clang on Windows targeting mingw-64/gcc building 64bit code", which was unanswered.

I use MSYS2/bash here. But just to be sure, i did the same test on cmd.exe,
and it worked. The --sysroot parameter is not even necessary if the 64bit
gcc is in the PATH (again, it must be in front of the 32bit).

I also tried with the Clang from http://llvm.org/builds/ and it worked.
That Clang doesn't need the 32bit mingw on PATH to run, because it is built
with MSVC. Can you try with it?

If you don't want to run the installer, you can exract it with 7-Zip or any
other extractor. Then put the mingw 64bit on PATH, and run:

clang++ test.cpp -static -m64 -pthread

That looks likea collision between the 32 bit and 64 bit versions of mingw.
Which version of 32 bit and 64 bit versions exactly do you, could you provide download links?
I ask because there are several mingw distributions around and they are different.

That looks likea collision between the 32 bit and 64 bit versions of mingw.
Which version of 32 bit and 64 bit versions exactly do you, could you
provide download links?
I ask because there are several mingw distributions around and they are
different.

The 32-bit version of mingw-64/gcc I am using is:

i686-5.1.0-posix-dwarf-rt_v4-rev0

The 64-bit version of mingw-64/gcc I am using is:

x86_64-5.1.0-posix-seh-rt_v4-rev0

I use the mingw-64 installer called 'mingw-w64-install.exe' to install various flavors of mingw-64.

If I run dependency walker on the 32-bit version of clang I have built from source with the 32-bit version of mingw-64/gcc above it shows a dependency in the clang++.exe on:

c:\utilities\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\LIBGCC_S_DW2-1.DLL
c:\utilities\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\LIBSTDC++-6.DLL

This means that the build of clang from source is linking to mingw-64/gcc 32-bit DLLs needed to run clang. So the build constrains clang to run only with the version of mingw-64/gcc with which it was built.

I did not change any of the default CMake build parameters that I know of. Is there a CMake build parameter which removes this constraint so that the version of clang is not dependent on the version of mingw-64/gcc with which it is built ?

That looks likea collision between the 32 bit and 64 bit versions of
mingw.
Which version of 32 bit and 64 bit versions exactly do you, could you
provide download links?
I ask because there are several mingw distributions around and they are
different.

The 32-bit version of mingw-64/gcc I am using is:

i686-5.1.0-posix-dwarf-rt_v4-rev0

The 64-bit version of mingw-64/gcc I am using is:

x86_64-5.1.0-posix-seh-rt_v4-rev0

I use the mingw-64 installer called 'mingw-w64-install.exe' to install
various flavors of mingw-64.

If I run dependency walker on the 32-bit version of clang I have built
from source with the 32-bit version of mingw-64/gcc above it shows a
dependency in the clang++.exe on:

c:\utilities\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\LIBGCC_S_DW2-1.DLL

c:\utilities\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\LIBSTDC++-6.DLL

This means that the build of clang from source is linking to
mingw-64/gcc 32-bit DLLs needed to run clang. So the build constrains
clang to run only with the version of mingw-64/gcc with which it was built.

I want to correct this. It does not mean that the build constrains clang to run only with the version of mingw-64/gcc with which it was built. But it does mean that when this clang runs it must find a LIBGCC_S_DW2-1.DLL and a LIBSTDC++-6.DLL in its PATH which it can use. Unfortunately the 64-bit versions of mingw-64/gcc do not support dwarf exception handling, which is where I think the dependency on LIBGCC_S_DW2-1.DLL comes from for the 32-bit version. The only common exception handling between the 32-bit and 64-bit versions of mingw-64/gcc is 'sjlj'. I will try building clang with a mingw-64/gcc 32-bit release that supports 'sjlj' exception handling and then see if it can run with a mingw-64/gcc 64-bit release that also supports 'sjlj' exception handling in order to create 64-bit code.

This has nothing to do with exception handling nor with clang specifically. This is a DLL dependency created for a program compiled with mingw 32 bits dwarf exception, dynamic linking to libgcc. The usual solution is to bundle the above DLLs along with clang*.exe at the same directory clang*.exe is. Another alternative is to build clang with the flags -static-libgcc -static-libstdc++ so that clang.exe will include a static copy of libgcc. Google “mingw static-libgcc dependency” for more explainations and examples.