简体   繁体   English

Visual Studio C++ 是否可以在不链接的情况下编译对象

[英]Is it possible for Visual Studio C++ to compile objects without linking

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).我正在运行 VS 2010 SP1,我有一个每周运行一次的特殊分析配置(因为构建服务器需要很长时间来分析所有内容)。

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.我看不出有什么方法可以告诉 VS 在不链接的情况下只运行 C++ 编译器。 Does anyone know of a way to do this within an existing vcxproj?有谁知道在现有的 vcxproj 中执行此操作的方法吗?

[Edit] Clarification: I'd like this to work from within the IDE. [编辑] 说明:我希望它能在 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.我的下一步行动是手动编辑 vcxproj 以查看我是否无法摆脱构建的链接阶段。

The C++ compiler cl.exe certainly can, that's the /c switch (compile only, don't link). C++ 编译器cl.exe当然可以,那就是/c开关(只编译,不链接)。 Not sure about the msbuild system that the IDE uses and that works with .vcxproj files, though.不过,不确定 IDE 使用的msbuild系统以及与.vcxproj文件一起使用的系统。

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.您可能还对/filelogger/fileloggerparameters选项感兴趣,它们可以让您捕获构建消息。

Just in this situation;就在这种情况下; trying to build without linking when using the IDE.在使用 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) .具体来说,从Application (.exe)更改为Static library (.lib) This will allow all your project(s) to build, but not require any linking to occur.这将允许您构建所有项目,但不需要进行任何链接。

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?".好的,我的问题并不完全具体,我应该问的是:“我可以在没有链接的情况下对 C++ 项目运行静态代码分析吗?”。

The recent answer is "Yes, with VS 2017 use the msbuild property RunCodeAnalysisOnce=true".最近的回答是“是的,在 VS 2017 中使用 msbuild 属性 RunCodeAnalysisOnce=true”。

Microsoft docs claim that this option is not available from within the development environment. Microsoft 文档声称此选项在开发环境中不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM