Is it possible for Visual Studio C++ to compile objects without linking
Asked Answered
P

4

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.

Puzzler answered 5/7, 2012 at 15:44 Comment(2)
From MSDN (msdn.microsoft.com/en-us/library/8we9bhf4.aspx) about /c switch: "This option is not available from within the development environment."Saccharide
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."Puzzler
B
3

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.

Balsam answered 12/4, 2014 at 22:24 Comment(1)
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).Puzzler
A
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.

Adkison answered 5/7, 2012 at 15:47 Comment(9)
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.Puzzler
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).Puzzler
@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.Adkison
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).Puzzler
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.Puzzler
@TimFiner: Both a semicolon and colon are valid syntax, and do different things. You want a colon.Adkison
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.Puzzler
@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.Adkison
I don't see "Compile" target at all in my solution.metaproj file. I'm using Visual Studio 2013, C++ projects. Any ideas?Sparke
B
3

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.

Balsam answered 12/4, 2014 at 22:24 Comment(1)
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).Puzzler
P
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".

Puzzler answered 15/10, 2018 at 17:10 Comment(0)
B
0

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

Bewilderment answered 21/5, 2021 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.