Finding all errors in Visual Studio C++ project - visual-studio

I have a C++ project in Visual Studio 2019. How do I find all cpp files with compiler errors? When I build solution, the compiler hits a file with error, then VS will declare the project build failed, and proceed to other projects. So I get only one of the errors.
When I use makefile to build, I could attempt to compile all modified files, then mark all the failed one. Can't Visual Studio do the same?
========
What I mean is that, I have a large project that has files a.cpp, b.cpp, c.cpp, in which I know b.cpp and c.cpp have errors. When VS builds the project, it detects error in b.cpp, then VS will not try to compile c.cpp. The build output is:
------ Build started:
a.cpp
b.cpp
"xx\xx\xx\b.cpp": error xxx: xxx
Done building project "project1.vcxproj" -- FAILED.
Building stops before compiler touches c.cpp.
And I found that this only happens in my large projects. In my small project VS will invoke compiler on all cpp files. The usual scenario is when I refactor some headers, I need to build the project again and again, fixing one cpp file at a time.

Build the solution "F6", then look at your error list Menu View -> Error List (alternatively, Ctrl + W, E). Then make sure under your error list tab, make sure "Entire Solution" is selected. This will list all of the compiler known errors and warnings within your project. As far as using makefile, you would have to debug within your Makefile specifically.
To answer your second question, unfortunately, there is no such
thing as a makefile debugger to examine how a particular rule is being evaluated or a
variable expanded, etc. Instead, most debugging is performed with simple print statements and by inspection of the makefile itself. This isn't handled by VS.

Related

Visual Studio project types Makefile and Utility

I am creating a vcxproj project to build C code (UEFI) which builds with custom build steps. I need the source C and H files to display with full IntelliSense support, then when I hit F5, I want the project to build if any source file changed, then start Debug. If nothing changed, just start the Debugger. The Build just needs to run my command line commands, I do not need Visual Studio to use its C compiler and Linker. It seems the only way to build with custom steps is to set Configuration Type to either Makefile or Utility.
One problem with Makefile project is that it always builds the NMake command line even if I did not touch any files. Is there a way to configure build so that it only builds if any of the source files changed, like with Application or Dynamic Library project types?
Another problem (only with Makefile project) is that it forces IntelliSense to some C++ mode that marks all my CHAR16* L"Strings" as errors: a value type of const wchar_t* cannot be used to initialize an entry of type "CHAR16*". There are Additional Options under NMake IntelliSense menu, but no matter what I put there makes no difference. There is no documentation about what the available switches are and their effect. Is it possible to configure a Makefile project to C mode? BTW, VS2013 does not have this problem, it is only VS2019 and VS2022.
Utility project type does not have the above-mentioned problem with IntelliSense, but it always returns "build up-to-date" even when I change source files, which should set a dirty flag and cause a build. The build only starts when I select Rebuild. Is it possible to configure a Utility project to build when a source file changed?

Does executable file get created if build fails in Visual Studio

Does executable file get created if Build Solution fails with some error in Visual Studio for c#?
Does Build Solution has to succeed in order to create executable file for the application in Visual Studio?
Thanks,
Ilya
This is actually a good question. The answer is: it depends.
There is a difference between "build" and "compile".
The "build" does a lot of work, like finding all the source files, resolving any references to assemblies and NuGet packages, and so forth.
The "compile" takes all those as inputs and produces an output assembly.
If the "compile" fails, then no output is produced (e.g. no .dll or .exe file).
However the "build" may fail after a successful "compile" (for example, if a post-build step fails) in which case the output file is created even though the build fails.
In 99.9999% of cases, a failed build means no output was produced, but it is not always the case.

Build Visual Studio Solution without Compile

Can Visual Studio build Solutions without a Compile step? I have a Pre-Build event that builds a .obj library and I just want the Visual Studio .sln to link against it. If I put a dummy Main.cpp file in the Solution, it will Compile that, then link against my Prebuild Event output. Without this dummy file though, the Linking never occurs.
I could put a Post-Build event Link in there, but the default Linking step has a lot of (Macro?) values that expand to directories that I would not want to try and mimic. I just want this VS Solution so it's easier as a link-only build script. The Pre-build event assembles some fasmg assembly sources.
Much appreciated..!
(This may be a duplicate question, but I could not find the duplicate. Will remove if so.)

Visual Studio run custom build tool when dependencies change

I have a solution with two C++ projects in Visual Studio 2013.
Project A creates a static library. Project B produces a SWIG-generated DLL wrapper for A, linking the lib generated by A. The complicating factor is that B generates code using a "Custom Build Step", set to execute before ClCompile. The custom build step calls out to an external tool to generate wrapper code based on classes defined in header files in project A. If the generation completes successfully, project B builds a DLL from the generated code, linking against the .lib generated in project A.
The problem I have is that the custom step in B is occurring on every build (as one would expect), but I'd like to make it happen when there are changes to header files in A. I can't see a way of defining a rule that enforces this condition. If I add "..\project A*.h" to the Additional Dependencies field of the Custom Build Step, the missing link would be a macro that evaluates to true when any file in Additional Dependencies is newer than any file in the Outputs field.
Does Visual Studio provide a macro that tells me when the Custom Build Step's Additional Dependencies are newer than Outputs, or am I in scripting territory here?
I use a custom build similar to this:
<CustomBuild>
<Command>swig -c++ -python -I..\include -outdir $(OutDir) %(Identity)</Command>
<Message>Creating SWIG-generated files...</Message>
<Outputs>$(ProjectName)_wrap.cxx;$(Outdir)$(ProjectName).py</Outputs>
<AdditionalInputs>header1.h;header2.h;header3.h</AdditionalInputs>
</CustomBuild>
I don't use anything additional, so Visual Studio seems to have a default rule to run the custom build step if files in AdditionalInputs are newer than Outputs.

How to compile all CPP file without building the whole project in VS2010

Is it possible that I can just compile all CPP files under a project and without linking etc. the project?
The only way I know to do this is by specify the /c switch when you compile the code. Unfortunately, this option is not available from within the Visual Studio development environment, so you'll need to build your code on the command line by calling cl.exe directly. To make things easy on yourself, use the Visual Studio Command Prompt to do so.
Not sure if it's possible to get MSBuild to do this, the documentation is unclear whether the limitation is Visual Studio itself or if it's a limitation of MSBuild. I haven't actually tried for myself.
Alternatively, you can build individual source files from within the IDE by pressing Ctrl+F7 (at least, assuming the default C++ development settings). If that fails, it's also available as the "Compile" option located in the "Build" menu.
I'm not sure whether this will do what you need, but may be worth a try: create a project for an executable (rather than a library) and include all cpp files in it. Add a main() function that just returns zero. Set the C++ optimisation option to 'optimise references' (/OPT:REF). This may just compile all the cpp files but effectively ignore them during the link stage since none of them are referenced by the application.
You don't say why you need to do this - is it because linking takes a huge amount of time?

Resources