Visual Studio Tips on getting headers that are used in a given project? - visual-studio

I have added all the header files from library in path how to get the headers that are only needed for the project

There's a compiler option that will produce a list of included files for a compilation unit in your Build Output window.
In the property page for the compilation unit, under the C/C++ Advanced section, there's an option called "Show Includes". Turn that on and recompile. You can probably do this on the project level as well, but I suggest you do it per compilation unit (.cpp) one by one.

Related

Visual Studio custom build tool doesn't rebuild from scratch

I have a generally question about "custom build tool" tab in settings.
I already used this feature and like it. But this time the result is not what I expected :/
I try to automatically convert a Performance Monitor manifest file (.man) to a corresponding .h and .rc file (ctrpp.exe). But this should not matter, just about the principle.
After I assign the custom step to the .man file, it is possible to compile the file in context menu. The build tool also recognize a modification and builds the output files again. Also the output files were deleted at rebuild.
But that's my problem.
Manual compile and inkremental build works fine, but why the files wasn't build automaticall after a first check out or at rebuild?? I expected that compiler forces a build, if it no output files found.
As result, the compiler don't find the corresponding header file in my files.
This page (in German) describes when the update is triggered. Can I force to generate the output files?

How to tell linker that I want my dll build in debug mode to have d suffix

I'm building a library in debug mode and it builds fine, but the built version of this library doesn't indicate in any way that it is built in debug mode. What I mean is that if the library is called mylib and after building it in debug mode I'm getting mylib.dll I don't really know in what mode did I built it. I'd prefer that I would have my output called mylibd.dll or mylib_d_.dll, but is this possible to specify something like it in Visual Studio 2015?
In Visual Studio you can have settings that differ per build configuration. Therefore, to achieve what you want, you would change the library names only for the Debug configuration.
In Solution Explorer, right click on the library in question, and go to Properties. Make sure the Configuration combo is set to Debug. Then, in Configuration Properties select the General group and change the Target Name setting as you like.
There are also several individual settings for the output files generated:
Linker/General/Output File
Linker/Manifest File/Manifest File
Linker/Debugging/Generate Program Database File
Linker/Advanced/Import Library
You can double check the full command line in Linker/Command Line to make sure all the filenames match your expectations.
Similarly, this can be done for static libraries as well. The appropriate configuration properties group in this case is called Librarian.

VStudio 2010 custom build issue

I use an Oracle precompiler for embedded SQL. I'm moving some code from VC++ 6.0 to VStudio 2010.
I place database calls in a single source code module named "dbcalls.pc" - that gets passed to the precompiler which produces "dbcalls.cpp" which then gets passed on to the compiler and linker like all other .cpp files.
Under VC6 I do a compile on my custom build .pc file manually - ie; rt click the dbcalls.pc file and choose compile. Then due to a bug in the specific version of the Oracle precompiler I use I have to open the .cpp and insert #include "stdafx.h" at the top of the .cpp produced by by the precompiler - I have a macro that does this. Then I can perform a build on the entire project and the VC6 IDE will NOT attempt to re-run the custom build.
In VStudio 2010, I have replicated this with one important exception/problem - if I configure the dbcalls.pc file to be excluded from the build under properties (where it is specified as being of type custom build) then I am unable to rt click the file and choose compile.
If I set the property to be included in the build I can rt click and manually build the .pc into the .cpp but then after I alter the .cpp when I run a build for the project it reruns the custom build and removes my changes. I'm forced to go back and forth with the properties dialog and change the "exclude from build" setting. This is a royal PITA that does not happen in VC6.
Can anyone suggest workaround? Obviously if the precompiler did not have this bug then all would be good but moving to another version of the pc is not currently in the cards.
thoughts?
OK - I'm not sure why - perhaps I swung the chicken over my head just the right amount of times.. - but it's working correctly now.
I resolved another issue I had with macro arguments to the precompiler in the custom build dialog and once I did that it started doing the conditional build correctly (or at least as I expected it to work).
Shrugged my shoulders a few times and said "case closed".

Why compile button is disabled in VisualStudio?

For some reason when I open my project Compile button is disabled. I'm in C++ file and Ctrl+F7 doesn't work, Menu/Build/Compile is disabled and Compile in context menu in SolutionExplorer is disabled too. I can build project with F7, but I can't compile single file. It used to work just fine.
Any ideas why?
Had the same problem just because my project wasn't set as startup Project in my solution. Setting it solve the issue.
It seems that problem is on my side: someone in my team introduced some build scripts, which apparently work only for building whole project.
It might also be that a referenced property sheet could not be found. You can check this by attempting to view the properties of the project (Alt-Enter). A warning will be shown then when the property sheet cannot be found. Fix the property sheet reference, and probably you can compile again.
Note: question was asked/answered a while ago, but maybe it is useful for other persons.
My project was using an intermediate version of a unity build (sometimes called blob build) where groups of ~10 cpp files are put in the same compilation unit by being included in some blob_xxx.cpp. The project only considers the blob_xxx.cpp as source files, so technically the .cpp I was working on was not a source file for the project, so the Compile command was disabled (this is similar to what Paulius experienced).
In this case, you need to either select the blob_xxx.cpp file and Compile this single file, or switch to a non-blob build.
If your objective is to quickly test for compilation errors, you can comment out the includes for all the files you are not working on.
Alternatively, you may setup your project generation script to isolate the files you are working on in a separate blob (it's up to you to define what "working on" means; it may be a manual list or the list of cpp files that are checked out in Perforce if using it).

Visual Studio - How to refrain from compiling all project files every build?

Each time I build my Visual C++ solution in Visual Studio 2010, the entire project (not the entire solution) recompiles.
There must be a flag or configuration somewhere to make VS compile only the changed files + depending files. Where is it?
UPDATES:
I set "Yes (/Gm)" to My project's configuration properties\C/C++\Code Generation\Enable Minimal Rebuild. It still compiles all the project's files upon F7.
If in addition you get the a message similar to:
Creating ".\Release\SomeLib.unsuccessfulbuild" because "AlwaysCreate" was specified.
when building, the reason might be that one of your projects refers to a header file which does not exist on disk (see here and here).
The first link also includes a small C# script to check for this situation. To fix, simply remove the reference to the non-existing header files from your project.
Update
It might be possible that you have your precompiled-headers setting on 'Create'. To fix, right-click your project in the solution browser and select: properties -> C/C++ -> Precompiled Headers -> Precompiled Header. Change the setting from Create to Use or Not Using Precompiled Headers.
VS should behave like you want it to by default; it sounds like something is flaky going on. Clean the project, and delete your settings files (e.g. .suo / vcproj..user / etc). There are several reasons for this, some of which I've seen are:
corrupt settings files
system date/time / time zone changes confusing vc
permissions issues on the source files
The post of tul was push forward for us, because we also have had some projects, which always did re-compile. As result I have found that:
yes, option 'Minimal Rebuild' somehow was corrupted in our visual 2010 projects. I guess, this could happens when they was transformed from visual 2005.
sign of "corruption" in a particular project is that this option is assigned, i.e. it is in bold. This could be only for some configurations, e.g. Release, or for some architectures, e.g. x64. It could be in bold "NO", but still recompiles.
FIX is as easy as the next steps:
select one or even few projects in solution
right click on project -> Properties
choose Configurations: "All Configurations"
choose Platform: "All Platforms" (if you have both x32/x64)
Expand C++ group
Goto "Code Generation"
note option "Enable Minimal Rebuild" -- most probably it will be empty, because different projects/configurations have different values
set this option to NO
click button Apply
again set this option to "inherited from parent"
click button Apply. NO you should see that this option becomes "NO" but in plain text.
DONE. No need even to recompile. The next build will be much faster.
So, I was having the same problem with one of our projects. First, I was able to debug the compiler output by selecting:
-> Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity -> Detailed.
It turned out that someone had set the project to always create precompiled headers for all files (/Yc). I changed the option as listed below.
-> Configuration Properties -> Precompiled Header -> Use (/Yu)
Then I set the same option for stdafx.cpp to (/Yc). So compilation of the stdafx.cpp creates the precompiled header, and all the other .cpp files use the precompiled header. This is the default scenario, and I'm not sure how it had changed for out project.
Additionally, I have changed all our compiler settings to be consistent across all projects, including:
1) Setting: C/C++ -> Precompiled Headers -> Precompiled Header -> Use (/Yu)
Switch: /Yu
Reason: Faster build time.
2) Setting: C/C++ -> General -> Debug Information Format -> Program Database for Edit and Continue
Switch: /ZI
Reason: Enables edit-and-continue, thereby improving debugging capability.
3) Setting: C/C++ -> Code Generation -> Enable Minimal Rebuild -> Yes
Switch: /Gm
Reason: Allow and speed up incremental builds and this is required for /ZI.
Hope that helps. I spent a lot of time messing with our project build settings and reading posts to Stack Overflow, and in the end, I miss C#.
I had the same issue, except mine started without reason, without me making any project configuration changes.
I would edit one file, hit build, and it would rebuild the entire project.
After much painstaking experimentation, I found that turning OFF 'Minimal Rebuild' made the problem go away. With that off, I could once more change a file and it would only compile that one file.
The weird thing was, once I had successfully made a build with minimal rebuild disabled, I could turn it back on, and everything was back to normal.
Makes me think that some cache file somewhere had become corrupted perhaps? I had tried deleting all my intermediary directories without joy, so if it was a corrupt file I don't think it was anywhere within my project directories.
Hope this helps.

Resources