5

when trying to use new clang with Visual Codegen in my project (Visual Studio 2015 Update 1), I'm getting following error:

clang.exe : error : cannot specify -o when generating multiple output files

This is just a newly created project with autogenerated main.

I really don't know what to do about it.

Any help appreciated.

RedX
  • 14,749
  • 1
  • 53
  • 76
Artur
  • 181
  • 1
  • 9
  • Well, the `-o` option states the name of the output file. The error message indicates that clang thinks it needs to generate *multiple* output files; why is that? – DevSolar Dec 01 '15 at 10:53
  • @DevSolar God only knows why clang thinks that it needs to output multiple files. – Artur Dec 01 '15 at 10:55
  • What does the command line look like? – DevSolar Dec 01 '15 at 10:56
  • Wait a sec DevSolar ;) – Artur Dec 01 '15 at 10:56
  • /Yu"stdafx.h" /GS /TP /W3 /Zc:wchar_t /ZI /Gm /Od /sdl /Fd"x64\Debug\vc140.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /MDd /Fa"x64\Debug\" /nologo /Fo"x64\Debug\" /Fp"x64\Debug\ConsoleApplication2.pch" – Artur Dec 01 '15 at 10:57
  • You are positive that's the command line that gets executed? Because those are parameters for Microsoft's compiler. I'd be surprised if clang could stomach those... – DevSolar Dec 01 '15 at 10:58
  • @DevSolar, well, that's the command line taken from dialog in VS. I really don't think there is any other command line. Although I may be wrong of course. – Artur Dec 01 '15 at 11:00
  • @DevSolar BTW, the clang is the clang shipped with VS 2015 Update 1 – Artur Dec 01 '15 at 11:00

2 Answers2

6

It is not very clear what you are doing but it seems obvious that you are not using one of the Clang project templates in the Cross Platform node. I can repro your problem by using the Win32 > Win32 Project template and changing the project's Platform Toolset selection to "Clang 3.7".

That doesn't work, it completely flubs the precompiled header feature. It is somehow convinced that it needs to compile stdafx.h. Not just once, it passes it the compiler twice. Which makes Clang barf with this error message, it will only accept one file at a time. It also doesn't know how to take advantage of Clang's PCH support, no sign of the required -emit-pch option.

You'll need to get ahead by turning the feature off. Project > Properties > C/C++ > Precompiled Headers > Precompiled Header = "Not using...". Select stdafx.cpp and repeat.

That solves the build problem, the final executable somewhat surprising runs without issue. It should be somewhat clear that you are using Clang in a scenario that was never tested by Microsoft. Looks like the IntelliSense parser is going to need a lot more work as well. Afaik Clang support was intended to target Android and iOS, current version is alpha quality.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

Just as an addition to the accepted answer, if you are still experiencing this issue even after setting Precompiled Header = "Not using...". The other issue might be an incorrect value in the Object File Name field.

That field can be found under: Project > Properties > C/C++ > General > Object File Name = $(IntDir)%(filename).obj

Note: originally discover this solution here: http://www.progtown.com/topic2009949-clang

Todd Bluhm
  • 185
  • 2
  • 9