Using Clang + Ninja on Windows?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Clang + Ninja on Windows?

Johan Holmberg
Hi!

How should I setup CMake to build a C/C++ application on Windows using clang/clang++ as compilers and Ninja as build tool?

I tried specifying "-GNinja" to cmake, and setting CC/CXX to clang/clang++. But this didn't work. I get errors like:

  clang.exe: error: no such file or directory: '/nologo'

indicating that CMake thinks it should pass Visual C++ style options to clang.

I'm thinking about fooling CMake that clang/clang++ are cross compilers (I know how to get cross compiling working in other cases). But since clang/clang++ are the native tools for Windows, I was hoping to be able to use Clang + Ninja on Windows almost like I use on Linux.

If I run Clang from the command line, I can build my application, so my Clang-installation works.

I'm using CMake 3.5.1 and Clang 3.8.0.

/Johan Holmberg


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Brad King
On 04/20/2016 10:01 AM, Johan Holmberg wrote:
> I tried specifying "-GNinja" to cmake, and setting CC/CXX to
> clang/clang++.

Good.

> But this didn't work. I get errors like:
>
>   clang.exe: error: no such file or directory: '/nologo'
>
> indicating that CMake thinks it should pass Visual C++ style
> options to clang.

There are multiple variants of Clang that behave like "gcc" or "cl".
Which one is this?  What installer did you use for Clang?

CMake should start out by printing the compiler id for the C and
CXX compilers.  What did it show?

Please try a minimum test project like

    >type CMakeLists.txt
    cmake_minimum_required(VERSION 3.5)
    project(Test)

in a fresh build tree and post the files

    CMakeFiles/CMake*.log
    CMakeFiles/*/CMake*Compiler.cmake

to see what CMake detected about the compiler.

Thanks,
-Brad

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Johan Holmberg


On Wed, Apr 20, 2016 at 5:54 PM, Brad King <[hidden email]> wrote:
On 04/20/2016 10:01 AM, Johan Holmberg wrote:
> I tried specifying "-GNinja" to cmake, and setting CC/CXX to
> clang/clang++.

Good.

> But this didn't work. I get errors like:
>
>   clang.exe: error: no such file or directory: '/nologo'
>
> indicating that CMake thinks it should pass Visual C++ style
> options to clang.

There are multiple variants of Clang that behave like "gcc" or "cl".
Which one is this?  What installer did you use for Clang?



I chose the binaries behaving like "gcc": After installation I added the "bin" directory to my PATH (actual command "set path=e:\work\install\LLVM\bin;%PATH%"). In the new bin-directory there are binaries called "clang.exe" and "clang++.exe" + a bunch of other binaries eg. "clang-cl.exe". I did NOT put the directory "e:\work\install\LLVM\msbuild-bin" in my PATH (containing a binary "cl.exe").

I realize that Cristian Adams recommended using the "cl.exe" wrapper in his response, but I wanted at least to try using the "gcc-like" binaries first, hoping that they should work with CMake. I will probably try his advice later, but as I understand it, both ways should be possible to get working with CMake.


CMake should start out by printing the compiler id for the C and
CXX compilers.  What did it show?


CMake starts by saying:

E:\work\proj\hello1\build> cmake -GNinja ..\src
-- The C compiler identification is Clang 3.8.0
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken
[...rest removed...]
 

Please try a minimum test project like

    >type CMakeLists.txt
    cmake_minimum_required(VERSION 3.5)
    project(Test)

in a fresh build tree and post the files

    CMakeFiles/CMake*.log
    CMakeFiles/*/CMake*Compiler.cmake

to see what CMake detected about the compiler.
Thanks,
-Brad



OK, I attach the files to this mail. There were three file created:

    build/CMakeFiles/3.5.1/CMakeRCCompiler.cmake
    build/CMakeFiles/CMakeError.log
    build/CMakeFiles/CMakeOutput.log

On my Windows machine I have Visual Studio 2008, 2012, 2013 and 2015. I used CMake 3.5.1 and Ninja 1.6.0.

/Johan Holmberg
 


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

CMakeOutput.log (1K) Download Attachment
CMakeError.log (1K) Download Attachment
CMakeRCCompiler.cmake (290 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Brad King
On 04/21/2016 10:15 AM, Johan Holmberg wrote:
> I chose the binaries behaving like "gcc"
>
> I realize that Cristian Adams recommended using the "cl.exe" wrapper in
> his response, but I wanted at least to try using the "gcc-like" binaries
> first, hoping that they should work with CMake.

I think that is the problem.  See below.

> E:\work\proj\hello1\build> cmake -GNinja ..\src
> -- The C compiler identification is Clang 3.8.0
> -- The CXX compiler identification is Clang 3.8.0

From the compiler id files you sent me I see:

    $ strings build/CMakeFiles/3.5.1/CompilerIdC/a.exe | grep INFO
    INFO:compiler[Clang]
    INFO:simulate[MSVC]
    INFO:compiler_version[00000003.00000008.00000000]
    INFO:simulate_version[00000018.00000000]
    INFO:platform[Windows]
    INFO:arch[x64]
    INFO:dialect_default[11]

    $ strings build/CMakeFiles/3.5.1/CompilerIdCXX/a.exe | grep INFO
    INFO:compiler[Clang]
    INFO:simulate[MSVC]
    INFO:platform[Windows]
    INFO:arch[x64]
    INFO:dialect_default[11]
    INFO:compiler_version[00000003.00000008.00000000]
    INFO:simulate_version[00000018.00000000]

The "INFO:simulate[MSVC]" lines mean that CMake has detected that the given
Clang compiler defines _MSC_VER and therefore acts like MSVC and not GNU
(i.e. uses the msvc ABI instead of the gnu ABI).

CMake then assumes that the compiler command line is compatible with "cl".
We have code that switches off this here:

 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/Platform/Windows-Clang.cmake;hb=v3.5.2
 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/Compiler/Clang.cmake;hb=v3.5.2

When all that was written clang-cl was still under development and our
assumption was that there is no such thing as a Clang that acts like
MSVC but is not cl-compatible on the command line.

-Brad

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Cristian Adam
In reply to this post by Johan Holmberg

On Wed, Apr 20, 2016 at 4:01 PM, Johan Holmberg <[hidden email]> wrote:
Hi!

How should I setup CMake to build a C/C++ application on Windows using clang/clang++ as compilers and Ninja as build tool?

I tried specifying "-GNinja" to cmake, and setting CC/CXX to clang/clang++. But this didn't work. I get errors like:

  clang.exe: error: no such file or directory: '/nologo'

indicating that CMake thinks it should pass Visual C++ style options to clang.

I'm thinking about fooling CMake that clang/clang++ are cross compilers (I know how to get cross compiling working in other cases). But since clang/clang++ are the native tools for Windows, I was hoping to be able to use Clang + Ninja on Windows almost like I use on Linux.

If I run Clang from the command line, I can build my application, so my Clang-installation works.

I'm using CMake 3.5.1 and Clang 3.8.0.

/Johan Holmberg


Hi,

On Windows Clang works only with Visual C++, since they don't provide libc++. MinGW is not supported.
Clang provides a Visual C++'s cl.exe replacement.

You need to have the official windows Clang and Visual C++ Express or Community installed.

Then it's just a matter of:
  1. Opening a Visual C++ 2013 64 bit command prompt window
  2. Putting clang's cl.exe in the path and setting clang's INCLUDE path first

    set PATH=c:\Program Files\LLVM\msbuild-bin\;%PATH%
    set INCLUDE=c:\Program Files\LLVM\lib\clang\3.8.0\include\;%INCLUDE%

  3. cmake -G "Ninja" 
  4. Ninja
CMake / Ninja will think that they compile with Visual C++, but instead will use clang.

Note that you have to match Visual C++ and Clang's build, 32 or 64 bit. You can't mix them,
or you'll have weird errors.

Cheers,
Cristian.

P.S. This is actually a re-post, this time adding the mailing list.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Gonzalo Garramuño


El 21/04/16 a las 18:30, Cristian Adam escribió:}

> Note that you have to match Visual C++ and Clang's build, 32 or 64 bit. You can't mix them,
> or you'll have weird errors.

I wonder.  Are the C and C++ ABIs of both compilers compatible?  That is, can I develop a program with clang but use visualc++ dlls or viceversa.


-- 
Gonzalo Garramuño
[hidden email]

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Mueller-Roemer, Johannes Sebastian
In reply to this post by Cristian Adam

You are mistaken, Clang absolutely also works with MinGW. Or it did at least up to 3.7 (didn’t get around to trying 3.8 yet)

 

From: CMake [mailto:[hidden email]] On Behalf Of Cristian Adam
Sent: Thursday, April 21, 2016 23:30
To: Johan Holmberg <[hidden email]>
Cc: [hidden email]
Subject: Re: [CMake] Using Clang + Ninja on Windows?

 

 

On Wed, Apr 20, 2016 at 4:01 PM, Johan Holmberg <[hidden email]> wrote:

Hi!

How should I setup CMake to build a C/C++ application on Windows using clang/clang++ as compilers and Ninja as build tool?

I tried specifying "-GNinja" to cmake, and setting CC/CXX to clang/clang++. But this didn't work. I get errors like:

  clang.exe: error: no such file or directory: '/nologo'

indicating that CMake thinks it should pass Visual C++ style options to clang.

I'm thinking about fooling CMake that clang/clang++ are cross compilers (I know how to get cross compiling working in other cases). But since clang/clang++ are the native tools for Windows, I was hoping to be able to use Clang + Ninja on Windows almost like I use on Linux.

If I run Clang from the command line, I can build my application, so my Clang-installation works.

 

I'm using CMake 3.5.1 and Clang 3.8.0.

/Johan Holmberg

 

Hi,

 

On Windows Clang works only with Visual C++, since they don't provide libc++. MinGW is not supported.

Clang provides a Visual C++'s cl.exe replacement.

 

You need to have the official windows Clang and Visual C++ Express or Community installed.

 

Then it's just a matter of:

1.       Opening a Visual C++ 2013 64 bit command prompt window

2.       Putting clang's cl.exe in the path and setting clang's INCLUDE path first

set PATH=c:\Program Files\LLVM\msbuild-bin\;%PATH%
set INCLUDE=c:\Program Files\LLVM\lib\clang\3.8.0\include\;%INCLUDE%

3.       cmake -G "Ninja" 

4.       Ninja

CMake / Ninja will think that they compile with Visual C++, but instead will use clang.

 

Note that you have to match Visual C++ and Clang's build, 32 or 64 bit. You can't mix them,

or you'll have weird errors.

 

Cheers,

Cristian.

 

P.S. This is actually a re-post, this time adding the mailing list.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Cristian Adam
On Fri, Apr 22, 2016 at 8:59 AM, Mueller-Roemer, Johannes Sebastian <[hidden email]> wrote:

You are mistaken, Clang absolutely also works with MinGW. Or it did at least up to 3.7 (didn’t get around to trying 3.8 yet)

 


Clang works fine with libstdc++ on Linux and Cygwin, there should be no reason why it shouldn't work with MinGW.

What I should have wrote was that Clang on Windows officially supports only a Visual C++ setup / Visual Studio integration.

I don't think I have seen a package containing clang and libstdc++ from MinGW.

Cheers,
Cristian.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Mueller-Roemer, Johannes Sebastian

It is true that there is no official bundled installer with both, but the official installer works just fine with mingw as long as you pass in the correct target to clang(++)

 

For example

clang++ --target=x86_64-w64-mingw32 test.cpp

 

However, it assumes that mingw64 is installed under C:/mingw64 (the default location, it’ll work with a junction point though).

 

 

From: Cristian Adam [mailto:[hidden email]]
Sent: Friday, April 22, 2016 09:15
To: Mueller-Roemer, Johannes Sebastian <[hidden email]>
Cc: [hidden email]
Subject: Re: [CMake] Using Clang + Ninja on Windows?

 

On Fri, Apr 22, 2016 at 8:59 AM, Mueller-Roemer, Johannes Sebastian <[hidden email]> wrote:

You are mistaken, Clang absolutely also works with MinGW. Or it did at least up to 3.7 (didn’t get around to trying 3.8 yet)

 

 

Clang works fine with libstdc++ on Linux and Cygwin, there should be no reason why it shouldn't work with MinGW.

 

What I should have wrote was that Clang on Windows officially supports only a Visual C++ setup / Visual Studio integration.

 

I don't think I have seen a package containing clang and libstdc++ from MinGW.

 

Cheers,

Cristian.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Using Clang + Ninja on Windows?

Edward Diener
On 4/22/2016 4:51 AM, Mueller-Roemer, Johannes Sebastian wrote:

> It is true that there is no official bundled installer with both, but
> the official installer works just fine with mingw as long as you pass in
> the correct target to clang(++)
>
> For example
>
> clang++ --target=x86_64-w64-mingw32 test.cpp
>
> However, it assumes that mingw64 is installed under C:/mingw64 (the
> default location, it’ll work with a junction point though).

As of clang 3.7 there is no need to have a hardcoded mingw directory.
You just need to have an appropriate mingw(-64)/gcc in your PATH. Also
all distributed versions of clang 3.4 through 3.7 for Windows default to
targeting mingw(-64)/gcc and not VC++. Only with 3.8 is the Windows
release defaulting to targeting VC++.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake