9

I'm running VS 2010 SP1 and I have a special analysis configuration that runs once a week (because it takes a long time for the build server to analyze everything).

I'd like this configuration to run without bothering to link. If the analysis passes for all the code in a project, then I'd like the build to just continue on to the next project without linking.

I can't see a way to tell VS to just run the C++ compiler without linking. Does anyone know of a way to do this within an existing vcxproj?

[Edit] Clarification: I'd like this to work from within the IDE.

My next course of action is hand editing the vcxproj to see if I can't get rid of the link phase of building.

Tim Finer
  • 565
  • 6
  • 13
  • From MSDN (http://msdn.microsoft.com/en-us/library/8we9bhf4.aspx) about /c switch: "This option is not available from within the development environment." – SChepurin Jul 05 '12 at 15:57
  • Yep, and the "/c" is already implicitly used, earlier in the doc: "Any internal project created in the development environment uses the /c option by default." – Tim Finer Jul 05 '12 at 16:47

4 Answers4

4

The C++ compiler cl.exe certainly can, that's the /c switch (compile only, don't link). Not sure about the msbuild system that the IDE uses and that works with .vcxproj files, though.

According to the documentation, this should work:

msbuild /target:Compile projectfile

or

msbuild /target:projectname:Compile solutionfile

You might also be interested in the /filelogger and /fileloggerparameters options, which let you capture build messages.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Yep, I know about /c, but that doesn't work (VS already does that when it compile each obj). I'm interested in doing this via the project file, so that the IDE will also honor this and not require running msbuild from the cmd line. – Tim Finer Jul 05 '12 at 16:50
  • Just for kicks I just tried the msbuild too, but it looks like I'd need to convert my solution (as my projects have references to solution variables). – Tim Finer Jul 05 '12 at 17:14
  • @Tim: `msbuild` allows you to pass in the solution file, and then there's another option to build a particular project from that solution. Hopefully that way the required variables are present. – Ben Voigt Jul 05 '12 at 17:56
  • Ah, yes, thanks, I also needed to add /p:Configuration=analysisCfg. /target:projectname:Compile doesn't work, alas (the target projectname:Compile doesn't exist). – Tim Finer Jul 05 '12 at 18:37
  • Ah, I was able to append **;Compile** and it is really a synonym for build, sigh. Note that it's a semicolon, not a colon. – Tim Finer Jul 05 '12 at 18:41
  • @TimFiner: Both a semicolon and colon are valid syntax, and do different things. You want a colon. – Ben Voigt Jul 05 '12 at 22:27
  • Hm, when I use a semicolon, msbuild does a regular build (compile, link, the works). When I try colon, is says MSB4057: the target "blah:Compile" does not exist in the project. Blah is the name of the project. In any case, unless colon does the single step of compilation at best this is almost what I want. Thank you for your answer anyway. – Tim Finer Jul 16 '12 at 14:57
  • @Tim: I guess the webpage that described the "Compile" action simply made it up, or maybe it applies just to a single source file. Colon is what you want for controlling both the project and the action (semicolon means a list of multiple projects to build), but maybe there isn't a "Compile" action for an entire project. – Ben Voigt Jul 16 '12 at 15:42
  • I don't see "Compile" target at all in my solution.metaproj file. I'm using Visual Studio 2013, C++ projects. Any ideas? – Mikhail Jul 13 '17 at 10:18
2

Just in this situation; trying to build without linking when using the IDE.

To achieve this for my configuration, I've altered the configuration type of my application:

General -> Project Defaults -> Configuration Type

Specifically, changing from Application (.exe) to Static library (.lib). This will allow all your project(s) to build, but not require any linking to occur.

jdknight
  • 1,801
  • 32
  • 52
  • Yep, I figured this out awhile back but never bothered to answer it. There you go! For future seekers, be sure to set this for the intended configuration (in my case, it was DebugAnalysis). – Tim Finer Apr 18 '14 at 01:14
2

OK, I wasn't completely specific in my question, what I should have asked is: "Can I run static code analysis on C++ projects without linking?".

The recent answer is "Yes, with VS 2017 use the msbuild property RunCodeAnalysisOnce=true".

Tim Finer
  • 565
  • 6
  • 13
0

Microsoft docs claim that this option is not available from within the development environment.

szdrnja
  • 194
  • 2
  • 6