Specify include paths individually per source file for Visual Studio C++ - visual-c++

Is it possible to specify include paths individually for each soucre *.cpp file?
Eclipse uses this method for code assistance, see Discovery Options properties
In Visual Studio 2010, all I can see is that one can only define the include paths project-wide.
It would be nice if this individual information could then be used for the IntelliSense compiler to parse only the current active source file.
As far as I know IntelliSense parses all files at once, which I think is not appropriate for verly large projects.

Related

How to inspect an external .cpp file?

I have in the project a cpp file that is outside the dir tree. Resharper c++ doesn't enable inspection, such as go to definition.
Resharper version 2022.1.2
Visual studio 2019 and 2022
It didn't help enabling
options> code editing> c++> inspection> enable on external modules
Also, it's not an external file, it's a cpp that is part of the project.
There's also this
https://www.jetbrains.com/help/resharper/Reference__Options__Tools__External_Sources.html
but the option doesn't appear under tools.
The problem is with resharper; VS inspection (go to definition) works fine.
I found the problem, and it's weird. Say I want to add to the project the file:
c:\prj\confstruct\src\debug\mpir.cpp
which is outside the project directory.
If in cmake I use the abs path (given as a parameter to add_executable):
/prj/confstruct/src/debug/mpir.cpp
then resharper ignores the file.
If I add the drive letter:
c:/prj/confstruct/src/debug/mpir.cpp
Then resharper works fine.
Make sure that the file is used somewhere in your project, i.e. is included into one of your .cpp files. Turn on the "Enable inspections, quick fixes and context actions in files external to the solution" option in ReSharper settings:

%(AdditionalIncludeDirectories) meaning

Think this will be rather simple but somehow I could not find a reference saying about this.
In the MSVC Include directories, there is an Additional Include Directories setting. The setting reads like this
..\Project1; %(AdditionalIncludeDirectories)
Understand the first part is the path for the program to search for additional program header includes. What about " %(AdditionalIncludeDirectories) " ? what does it mean?
It does not seem to be a macro which I understand is headed by "$" eg $MACRO
Thanks
Answer
In the documentation for Working with Project Properties there is a section on "item macros":
Item macros
Has the syntax %(name). For a file, an item macro applies only to that fileā€”for example, you can use %(AdditionalIncludeDirectories) to specify include directories that apply only to a particular file. This kind of item macro corresponds to an ItemGroup metadata in MSBuild. When it's used in the context of a project configuration, an item macro applies to all files of a certain type. For example, the C/C++ Preprocessor Definitions configuration property can take a %(PreprocessorDefinitions) item macro that applies to all .cpp files in the project. This kind of item macro corresponds to an ItemDefinitionGroup metadata in MSBuild. For more information, see Item Definitions.
Discussion
I had exactly the same problem in a project I am taking over from a former developer : his Additional Include Directories are C:\Users\t-tshmit\Downloads\DirectXTK;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)
And oddly the %(AdditionalIncludeDirectories) element is not included in the edit box
Looking around the web I could not find much on this, but it is clearly a pattern in use, for example the screenshot used in http://www.steptools.com/support/stdev_docs/help/settings_vc10.html may contain the %(AdditionalIncludeDirectories) element.
The documentation for both the Additional Include Directories compiler options and the AdditionalIncludeDirectories VCCL Compiler Tool property contain no mention of this %(NAME) pattern.
https://learn.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties?view=vs-2019
They are called "item metadata macros."
The build system for C++ was significantly changed between Visual
Studio 2008 and Visual Studio 2010. Many macros used in earlier
project types have been changed to new ones. These macros are no
longer used or have been replaced by one or more equivalent properties
or item metadata macro (%(name)) values. Macros that are marked
"migrated" can be updated by the project migration tool. If the
project that contains the macro is migrated from Visual Studio 2008 or
earlier to Visual Studio 2010, Visual Studio converts the macro to the
equivalent current macro. Later versions of Visual Studio can't
convert projects from Visual Studio 2008 and earlier to the new
project type. You must convert these projects in two steps; first
convert them to Visual Studio 2010, and then convert the result to
your newer version of Visual Studio. For more information, see
Overview of potential upgrade issues.

Visual studio - set file location

I have a VS project, but I moved some source, resource files to another location.
It's not easy for me to readd all again (cause of filled properties tab for custom build tools, etc.)
Is there any easy GUI way to change the included source file path? In XCode it's easy to do this, but I don't see any way in Visual Studio (currently using 2012).
Do I have to rewrite the xml build file?
I have finally find it. Easiest way is to edit the xml file .vcxproj. I just have to manually find the paths (they are relative... i dont really know why Microsoft did this, it is so stupid) in that xml and edit it.

Configure a Visual C++ 2010 project to use include folder as in Linux

I'm porting a Linux C project in Visual Studio 2010.
I have the following folder project structure under linux:
ProjectName->Src->Source C files
ProjectName->Header->Source H files related to C
How should I configure Visual Studio 2010 to recreate the same structure without compile errors ?
How to create the include folder and tell to the the compiler that is an include folder.
I cannot even add include files (existing elements) in a simple folder. They simply don't appear as I add it.
On the C/C++ configuration tab is the Additional Include Directories option. Set it to the following:
$(ProjectDir)/Header
That should do it. Don't forget to do it for all your configs (debug, release, etc).
Oh, and regarding adding new header files, when you open the Add.. option to add a new file, pay close attention to the BOTTOM of the dialog. it will tell you where it will be placed, and you can change it there.

Loading Boost 1.40.0 into Intellisense in Visual Studio 2005?

Is there any way to get Intellisense in Visual C++ for Visual Studio 2005?
I'm trying to get the Boost libraries to load up with intellisense and in the object browser/class view.
I installed the binary for Windows with the BoostPro installer (BoostPro 1.40.0 Installer).
I'm not certain that it comes with the source code however, which may be required to make Intellisense work in VS2005.
Boost is open source, and mostly header only. Just make sure IntelliSense knows the directory where boost resides so it can explore it.
As an un-answer, you might try out Visual Assist X, which works far better and has more features that Visual Studio's IS.
To make sure Intellisense can find boost, just make sure Boost is in the include directories (under Project Properties->C/C++->Additional Include Directories). Maybe move it to the top. After that, close your instance of Visual Studio, and search the a *.ncb file near your project, and delete it. This will cause IntelliSense to refresh. This should hopefully be enough for it to assist you. (You have to include boost headers into your source files with #include for IntelliSense to consider it)
Keep in mind boost has some very complex parts that IS will choke on, but should still provide the names.
Intellisense scans the headers #included in source files in Visual C++ projects.
So create a project with a single source file that includes the top level header of the boost library that you're interested in. Some of the boost code can't be parsed by intellisense though, and the boost code contains a lot of code to workaround language or compiler limitations that's just noise to someone wanting to see the user facing structure of the libraries.

Resources