How to avoid stdafx and other header files [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
When creating a new C++ Windows Application in Visual Studio 2017, I am always given an stdafx.cpp file, as well as stdafx.h and targetver.h files. I am taking an Intro Programming class and the instructor thoroughly disapproves of these files being included in our projects. I am using a Mac with BootCamp to run this compiler properly, and I am able to write my code and run it fine - but I need to get rid of these extraneous files that are included with my project.
My professor's suggestion was to instead create an Empty Project when initially making the project, but this must leave out some type of necessary libraries/headers because my same code will misbehave with functions like "cout". (builds fine).
Put simply, how can I create a new project that is empty besides my cpp file, and behaves as normal?

You can create a new project and disable use of of precompiled headers and please also select Empty Project while creating. If you don't intend to create a new project file, you can do this in the existing project file.To do this, do the following -
Select your project, use the "Project -> Properties" menu and go to
the "Configuration Properties -> C/C++ -> Precompiled Headers"
section, then change the "Precompiled Header" setting to "Not Using
Precompiled Headers" option.

when you create a project with visual studio ,you'll have the option "use pre compiled headers" which you can disable !
NB Just discovered that the new update (15.3.5) of vs2017 has changed the creation of projects a little and seems to offer this only when choosing Windows desktop wizard !

Related

How do I properly compile and link a resource file using MSVC command line toolchain? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am a beginner to Windows API, and trying to learn how to make applications and such. I got to this part in the winprog.org articles, where the author started using resource files. I have written the resource file, in the .rc format. I compile it using the rc command, and it compiles into a .res file. Then I pass it off to the linker along with the the main object file, again, all from the command line. But when I run the linked executable, it does not show me the menu I defined in the resource file. Nor the icon I specified in there.
I am using Visual Studio Code instead of Visual Studio, partly to get comfortable with the MSVC CLI, and partly because I just like VSCode better. I also don't want to install additional C/C++ compilers when I already have MSVC.
So,
How should I go about compiling and linking the resource file correctly?
Are there any more up-to-date and not nightmarish methods to learn how to work with the Windows API?
You compile the resource script using the Resource Compiler (rc.exe) and pass its output on to the linker. There is no other magic involved.

Trouble with Visual Studio [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Ok, so I create a project.
Now I create two c++ classes in that project A and B.
A has some compilation errors. B is just fine and compiles fine.
Now, when I run B, it wouldn't run because A still has compilation errors.
So, I don't like to create a whole new project just because I want to create a new c++ file (scratch to experiment on) and toggle between the two projects.
Is there any way I can just have two c++ files existing independently in a single project?
In the current scenario, how do i build/compile and run only one of the c++ file (A or B) without the other one getting compiled and run as well.
This is why I never made the transition from sublime to VS.
First Question: In Visual Studio, in your Solution Explorer, right click under your project and select "Add>New Item" and then select your code file format in the Window that pops up(C++ in your case). Enter a name for the file and then click the "Add" button.
Second Question: In the solution explorer window, right click the file that you do not wish to be included in the project and select "Exclude from Project". That file will not be compiled, but will still be visible in Visual Studio. When you want to include the file, same procedure: Right click the file, select "Include in project".

Are there any tools for reviewing include or import code structure/hierarchies? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a tool (preferably, a Visual Studio plugin) that would display all files included by a given file and show all files included by those files and so on.
First, cinclude2dot.pl is a perl script which analyses C/C++ code and produces a #include dependency graph as a dot file for input into graphviz.
http://www.flourish.org/cinclude2dot/
If you don't want to go the way of that sort of manual tool, then the hands-down by far winner is in my opinion a tool known as "IncludeManager" from ProFactor.
http://www.profactor.co.uk/includemanager.php
There's a free trial, and it is awesome. It's a plug-in for Visual Studio that's totally integrated so double clicking on something over here takes you to the place where it is included over there.
Tooltip mouseovers give you all the info you would want, and it lets you drill down / up, remove whole subtrees you don't care about, view representations other than graphs, cycle through a list of matches for this and that, it's wonderful.
If you're quick about it, you can refactor the #include structure of a large projects before the trial runs out. Even so, it doesn't cost much, about $35 per license.
For what it does, it is just about perfect. Not only #include graphs but also cross project dependencies of shared files, impact on build times, detailed properties in grids, perfect.
Doxygen, with the aid of Graphviz, can do that. You first need to edit a configuration file. This won't be easy the first time you do it, but no much editing is needed afterwards.
Not quite what you want perhaps, but the Visual Studio compiler (cl.exe) has an option /showIncludes which will show you a tree of the includes when you compile a file.
If you want this information for a single file then you can right-click on the file in the Solution Explorer, select "Properties", and in the "Command Line" section just add /showIncludes to the "Additional Options". (Note I'm using VC++ 2005, so it may be different for newer versions).
The output that you get is a little... convoluted, but it shows you what gets included and in what order.
Incidentally, the same feature in GCC and the Intel C++ compiler (my versions at least) is -H.
You can try the method suggested by this Stack Overflow answer:
There is a C/C++ -> Advanced project setting "show Includes". That
will generate the tree. It maps to the compiler switch /showIncludes
If you are using Visual Studio 2010 you can use the new Visualization and Modelling Feature Pack from Microsoft, which has a feature to generate an include graph. This is only available through an MSDN subscript though.
Not in your preferences, but doxygen does that quite well.
http://www.codeproject.com/KB/applications/includefinder.aspx
This is not a VS plug-in but can be a starter for your own tool. As far as I could see it reads VC6 projects only, the newer VS have an XML format easy to parse. What you need out of it are the default include paths so the tool can find the included files. Alternatively you could provide a settings box for it in the GUI as user input.

How to set Intellisense of Visual Studio2010 about c++? [duplicate]

I can't get intellisense to work. Even if I start with an empty project and add just one file to it with only an include for iostream and an int main() function that prints a char with cout (basically the most basic program), if I try to get intellisense to show anything (say by typing cout.) I get
IntelliSense: 'No additional information available' (See 'Troubleshooting IntelliSense in C++ Projects' for further help.)
Hours of googling have yielded a couple of articles over at the Microsoft sites that suggest a bunch of things to try or reasons why it wouldn't work. I have tried and eliminated them all, except for one that mentions that stdafx.h has to be in the path.
What is this file?
How do I know if it is in the path if I don't know where it is?
What does it have to do with IntelliSense?
Should I add this file to my project to get it to work?
Thank you.
I got it solved by the Microsoft team at http://connect.microsoft.com/VisualStudio/feedback/details/652838/intellisense-not-creating-ipch-folder
It had to do with a certain Windows Update installed on WinXP. The solution was to install VS2010_SP1 and then a certain update over it.
Look at this question :C++ VS Express 2010 Intellisense
It was solved by pressing CTRL+J .
EDIT: maybe it's the stdafx.h problem !
Add a file stdafx.cpp and a file stdafx.h to the project !
Use #include "stdafx.h" as yhe first line of code in all your .cpp files.
Include all rarely/never changing and frequently used header-files in stdafx.h.
Turn on precompiler-headers in your project and rebuild the project.
(Create a dummy project which have precompiled headers on to see how it's been done)
Do you use the /UseEnv switch when opening visual studio? It breaks Intellisense for c++ projects.
Please find *.sdf file (Intellisence database cache) in project directory and delete it and relaunch project solution this will bring back your intellisence.
There are a couple of threads about similar problems:
click on Help at VS2010 and look for Intellisense.
http://social.msdn.microsoft.com/Search/en-US?query=intellisense%20settings&refinement=123&beta=0&ac=1
http://social.msdn.microsoft.com/Forums/en/vswpfdesigner/thread/75c4cc8d-9a81-4bda-84f0-f619f7493b3b
stdafx.h should be added automatically when you create a New Project.
From the file:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
Just throwing this out there, you are using namespace std? eg:
std::cout.
because intellisense wont work if it doesn't see cout
edit: I over looked that error message so this isn't the case but leaving the answer in case it might help someone down the line.
Maybe it never got installed, have you tried a repair install?, it's worth a shot..
I thought I should mention this:
In Visual Studio 2012 I noticed that Intellisense suddenly stopped working in my C++ project (same error as the poster described). This happened because I had added "DEBUG" as a Preprocessor definition under Project Properties -> C/C++ -> Preprocessor.
Once I removed it from that list and instead put it in the code ( #define DEBUG ) intellisense suddenly started working again.
I don't know why this happens, I just know it screws up my intellisense. I hope this helps someone.
WIN32;_WINDOWS;_DEBUG;Append _DEBUG;
remove Append _DEBUG;
baruch's answer worked for me. for completion, here is also the link to the VS2010-SP1:
http://www.microsoft.com/en-us/download/details.aspx?id=23691
so first installing this and then the hot-fix that baruch referred to solved me the problem, although the whole installation took almost 1:30 hour! (including one restart on my Win-XP machine.)
I know this is an old question, but I had a similar problem IntelliSense: 'No additional information available' (See 'Troubleshooting IntelliSense in C++ Projects' for further help.). My problem wasn't related with stdafx.h.
To solve my problem, I closed VS2010, deleted the .sdf and .suo files as well as the ipch directory inside the project's main folder.
Then I restarted VS2010, waited for it to build all its metadata again and Intellisense (autocompletion) worked nicely.
EDIT: I am not aware if this "maneuver" has negative side effects.
IntelliSense stores it's data in the SQL Server, which is installed during VS2010 setup. I recommend you check if the SQL Server Service is running.

Build a C++ project with debug files [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a Visual Studio solution in C++ containing 27 projects with known build order and everything else, I can successfully build entire solution and everything works fine, As you know after building each project some files will produce in "Debug" (or "release") folder and I access to them for each project, 26 projects of this solution needs no change, I just want to change one project, So I just wondered if I can use produced debug files of all 26 other projects and build my solution again in Visual Studio or any other IDE?
Thank you so much
The 'debug files' of visual studios are *.pdb files and are a proprietary MS format and therefore cannot be used in other IDEs:
What is the structure of a PDB file?
The intermediate files of VS '*.obj' are generated for every translation unit but a conversion to another compiler is not achievable in an easy way:
Is there a tool that can convert a Visual Studio object file to GCC format?
If you already have the VS solution you can make changes to the project you want to edit and VS will ensure that every project that needs a change will be recompiled and linked if you build the solution.
If you want to spare time you can tell VS compile the project you are working on instead the entire solution. You might stay with VS if that works for you.
Adding support for another build-system or IDE should be done by an experienced developer who is familiar with those projects.
In theory, Visual studio will spot what has changed (in a solution) and just saying build should just build what has changed (and its dependencies).
Beware if using the libraries and exes from one compiler with those of another - you almost certainly need to use the same version of Visual Studio, since for example the implementations of the stl will change between version.
Furthermore, if you use a different compiler things will almost certainly go horribly wrong.
If you use another IDE and point it to the same compiler, things should be ok.
edit
If by "another IDE" you mean another instance of the same IDE, i.e. you want to open a different solution, but use this as a "library" that's fine. You don't need the .obj files - they are part of the build process. It's the final .lib or .dll files you need, together with .pdb files if you want the debug symbols.