Using Clang With CLion on Windows
Hi, I am trialing CLion to evaluate whether we should make it our primary IDE for our open source project.
Is it possible to use clang as the compiler on windows since it is supposed to be a drop in replacement for gcc?
I compiled clang on windows and tried to set my CMAKE_CXX_COMPILER variable to point to this compiled clang. CLion looks like it does some sort of auto generation and I get these errors. Any help would be great!
Error:Error:The C++ compiler "C:/Users/Michael/Desktop/Clang/build/Debug/bin/clang.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/Michael/.clion11/system/cmake/generated/a1cb0336/a1cb0336/__default__/CMakeFiles/CMakeTmp
Run Build Command:"C:/MinGW/bin/mingw32-make.exe" "cmTC_df521/fast"
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_df521.dir\build.make CMakeFiles/cmTC_df521.dir/build
mingw32-make.exe[1]: Entering directory 'C:/Users/Michael/.clion11/system/cmake/generated/a1cb0336/a1cb0336/__default__/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_df521.dir/testCXXCompiler.cxx.obj
C:\Users\Michael\Desktop\Clang\build\Debug\bin\clang.exe /nologo /DWIN32 /D_WINDOWS /W3 /GR /EHsc /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 /FoCMakeFiles\cmTC_df521.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_df521.dir/ -c C:\Users\Michael\.clion11\system\cmake\generated\a1cb0336\a1cb0336\__default__\CMakeFiles\CMakeTmp\testCXXCompiler.cxx
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/DWIN32'
clang.exe: error: no such file or directory: '/D_WINDOWS'
clang.exe: error: no such file or directory: '/W3'
clang.exe: error: no such file or directory: '/GR'
clang.exe: error: no such file or directory: '/EHsc'
clang.exe: error: no such file or directory: '/D_DEBUG'
clang.exe: error: no such file or directory: '/MDd'
clang.exe: error: no such file or directory: '/Zi'
clang.exe: error: no such file or directory: '/Ob0'
clang.exe: error: no such file or directory: '/Od'
clang.exe: error: no such file or directory: '/RTC1'
clang.exe: error: no such file or directory: '/FoCMakeFiles\cmTC_df521.dir\testCXXCompiler.cxx.obj'
clang.exe: error: no such file or directory: '/FdCMakeFiles\cmTC_df521.dir/'
CMakeFiles\cmTC_df521.dir\build.make:64: recipe for target 'CMakeFiles/cmTC_df521.dir/testCXXCompiler.cxx.obj' failed
mingw32-make.exe[1]: *** [CMakeFiles/cmTC_df521.dir/testCXXCompiler.cxx.obj] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/Michael/.clion11/system/cmake/generated/a1cb0336/a1cb0336/__default__/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_df521/fast' failed
mingw32-make.exe: *** [cmTC_df521/fast] Error 2
CMake will not be able to correctly generate this project.
Error:Error:Configuration Debug
Please sign in to leave a comment.
Hi Michael.
Please see this conversation. Does that help?
I am sorry, but it doesn't - I've already gone through the steps of setting the CMAKE_CXX_COMPILER in addition I am trying to use clang via MinGW, not Cygwin. My problem appears identical to this stack overflow user, who never actually had their question answered: http://stackoverflow.com/questions/30945416/attaching-a-different-compiler-other-than-gcc-to-clion-ide-on-windows.
I guess the better question to ask is whether anyone has gotten CLion working with Clang (leaning on MinGW) on Windows. If so, then I am probably just doing something silly and can figure it out in time. However, I don't want to waste time if it isn't even verified to be compatible.
Michael,
I was wondering if you got this to work. I have not and I think I know why. I will try to explain as briefly as possible. I note that the compiler arguments passed to g++ are on the linux/mingw type, i.e. g++.exe -o -std=c++11, etc. whereas the clang arguments are windows style, i.e. clang++.exe /O /DWin32, etc. (note: these aren't real args, i'm just typing off top of head to show syntax difference).
i note that the target for g++ via mingw is something like x86_64-w64-mingw whereas the target in llvm/clang is x86_64-pc-windows-msvc
furthermore, i looked closely at the requirements for CLion on the various platforms and clang compiler is only specified for OSX and linux.
this leads me to believe that clang for clion on windows is not supported. i would be willing to bet that it will be in the future, though.
please let me know if you have figured out how to get it to work, though!
Yeah, I can get Clang to run on Linux. Can't get it to run on Windows. On Linux at least Clang accepts gcc arguments. Everything compiles without issue, but I get a memory error When running my application.
Cygwin runtime failure: /cygdrive/c/Users/Zerophase/.CLion2016.2/system/cmake/generated/xml_parser-cbbe4cfd/cbbe4cfd/Debug/XML_Parser.exe: Invalid relocation. Offset 0x2fb03251f at address 0x10040243d doesn't fit into 32 bits
Edit: I just want to make it clear that error message happens when trying to run an application, on Cygwin with Clang.
Same would love some directions on how to use clang on Clion on Windows
I have the same problem with setting cmake options "-DCMAKE_C_COMPILER=D:/apps/LLVM/bin/clang.exe -DCMAKE_CXX_COMPILER=D:/apps/LLVM/bin/clang++.exe"
Here is the detail error message.
"D:\apps\JetBrains\CLion 2017.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=D:/apps/LLVM/bin/clang.exe -DCMAKE_CXX_COMPILER=D:/apps/LLVM/bin/clang++.exe -G "CodeBlocks - MinGW Makefiles" C:\Users\Liu.D.H\CLionProjects\hello
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: D:/apps/LLVM/bin/clang.exe
-- Check for working C compiler: D:/apps/LLVM/bin/clang.exe -- broken
CMake Error at D:/apps/JetBrains/CLion 2017.3/bin/cmake/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "D:/apps/LLVM/bin/clang.exe" is not able to compile a simple
test program.
It fails with the following output:
Change Dir: C:/Users/Liu.D.H/CLionProjects/hello/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command:"C:/MinGW/bin/mingw32-make.exe" "cmTC_78dd9/fast"
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_78dd9.dir\build.make
CMakeFiles/cmTC_78dd9.dir/build
mingw32-make.exe[1]: Entering directory
'C:/Users/Liu.D.H/CLionProjects/hello/cmake-build-debug/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_78dd9.dir/testCCompiler.c.obj
D:\apps\LLVM\bin\clang.exe /nologo /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od
/RTC1 /FoCMakeFiles\cmTC_78dd9.dir\testCCompiler.c.obj
/FdCMakeFiles\cmTC_78dd9.dir/ -c
C:\Users\Liu.D.H\CLionProjects\hello\cmake-build-debug\CMakeFiles\CMakeTmp\testCCompiler.c
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/DWIN32'
clang.exe: error: no such file or directory: '/D_WINDOWS'
clang.exe: error: no such file or directory: '/W3'
clang.exe: error: no such file or directory: '/MDd'
clang.exe: error: no such file or directory: '/Zi'
clang.exe: error: no such file or directory: '/Ob0'
clang.exe: error: no such file or directory: '/Od'
clang.exe: error: no such file or directory: '/RTC1'
clang.exe: error: no such file or directory:
'/FoCMakeFiles\cmTC_78dd9.dir\testCCompiler.c.obj'
clang.exe: error: no such file or directory:
'/FdCMakeFiles\cmTC_78dd9.dir/'
CMakeFiles\cmTC_78dd9.dir\build.make:64: recipe for target
'CMakeFiles/cmTC_78dd9.dir/testCCompiler.c.obj' failed
mingw32-make.exe[1]: *** [CMakeFiles/cmTC_78dd9.dir/testCCompiler.c.obj]
Error 1
mingw32-make.exe[1]: Leaving directory
'C:/Users/Liu.D.H/CLionProjects/hello/cmake-build-debug/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_78dd9/fast' failed
mingw32-make.exe: *** [cmTC_78dd9/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Liu.D.H/CLionProjects/hello/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Liu.D.H/CLionProjects/hello/cmake-build-debug/CMakeFiles/CMakeError.log".
[Failed to reload]
Step 1: Install mingw-64 carefully.
Go to the mingw-64 formal web site (url: http://mingw-w64.org/doku.php )
Follows the downloads links to install the msys2.
http://mingw-w64.org/doku.php -> http://mingw-w64.org/doku.php/download -> http://www.msys2.org/
Step 2: Launch the msys terminal and install llvm/clang (64 or 32bit).
pacman -S mingw-w64-x86_64-llvm mingw-w64-x86_64-clang
Step 3: Let CMake detect clang from the environment variables.
Step 4: Rebuild the project workspace.
Tools -> CMake -> Reset Cache and Reload Project
Reference:
https://stackoverflow.com/questions/7031126/switching-between-gcc-and-clang-llvm-using-cmake/12843988
What should I do if I have to use clang-cl?