Visual Studio: C++ Project Include Paths sharing over Repository - c++

I was wondering how should I add my library include paths and linker paths in Visual Studio so that when I add my project to a repository, another developer checking out my project would not need to go through all the include paths and change them for his own machine. So, I am kind of looking at something like ${MY_THIRD_PARTY_LIB_INCLUDE_PATH}\tbb\include and ${MY_THIRD_PARTY_LIB_LINKER_PATH}\tbb\lib\ia32\vc11 so that someone accessing the project can just change MY_THIRD_PARTY_LIB_INCLUDE_PATH and MY_THIRD_PARTY_LIB_LINKER_PATH and everything works as intended. Can somebody suggest a best practice around this or may be how to accomplish what I just described?

In VisualStudio 2012 I use Project Properties
So if you go to the Propery Manager you Add a new Project Property Sheet to you project. From there, a couple of things can be set
User Macros - We create a macro here and put in a path for our environment. We crate a Macro called CUSTOM_DEBUG_PATHS, and then in the project we set the Debugging->Environment to path=$(PLA_DEBUG_PATHS);$(PATH)
The other thing that we do in the Project Property Sheet is change our Include and Library directories. We have everyone use relative paths, but you could put in an environment variable or something in here so that everyone could use the same file.

Related

How do you seamlessly integrate a third party library into Visual Studio 2017?

I want to take libFoobar/lib and libFoobar/include and tell VS2017 to make compiling and linking with them work by default for all projects.
In earlier versions there was a global setting for compiler directories but I believe they deprecated that and made it completely project level.
You can manually add a third party library to a project by configuring its project settings
Under C/C++ / additional include directories and linker / input / additional dependencies.
I don't want to have to store or memorize the names and locations of all of the .lib files or /include directories that I might need and manually re-enter them every time I start a new project or have to recreate an existing project.
There may be a way to create and maintain a project template which would be a solution.
You can add .libs to the project from the source code via #pragma comment(lib, "libFoobar.lib"). The most convenient overall method that I've got so far is to add /libFoobar/lib to the PATH variable, add the libs via #pragma to each header file, and manually add the /include directory to each project. But that's a hack.
I did try to use "INCLUDE" and "LIBPATH" environment variables but they did not exist and adding them did nothing:
https://learn.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=vs-2019
They might be valid on 2019 only.
Yes, project templates are a thing, and should accomplish this.
Here's some documentation I found by Googling "VS project templates":
How to: Create project templates
Instead of making project templates you can modify the default project property sheets.
Go to View->Other window->Property manager then open one of the nodes for the machine type you are working with (debug and release builds share the actual property sheet file). Right click on Microsoft.Cpp..user and select Properties, you can then make changes just like any other property sheet and the settings will be picked up by projects generated using the default wizards.
This is the replacement system for the mentioned prior global setting.

Setting default additional include/library paths in a Visual Studio C++ project

Maybe I just did not really search for the right keywords yet, but I couldn't find a decent post about this.
The thing I want is that everytime I create a new c++ project, it should automatically add additional include and library paths into the project. Is there something like a default configuration manager or something similar? It really gets annoying to always add the same include paths and library paths into all the projects.
Thanks in advance for any help!
You can choose the empty project option when creating your project, so you don't include unnecessary library paths. I hope I can help you!

Using sub projects in Visual Studio

I am quite used to Linux development and Makefiles, and started using (Windows and) Visual Studio not so long ago.
What I want to do is (I think) quite simple, but I can't seem to find how to do it using Visual Studio.
I have to write an application, which I can divide into several independent sub-parts. I want to work incrementally, and create several projects that together with a main file will end up with my full project.
What I basically want is to be able to write a small project, have a main for it so that I can fully test it, and use it as a dependency for the next project. In this case, the smaller main would be deactivated (or I can comment it), and I would just change the startup project.
If I find a bug in a subset while writing my bigger software, I could just change the startup project and solve it at a smaller scale.
Well, that's what I do all day long in Python and Java.
I tried to create new projects into my project, but I always end up having linking problems, where my main projects knows about the files in the sub projects, but not the smaller ones, etc. . .
So, is there a guide somewhere I can find to work this way ?
Thank you
For individual projects:
Every individual project property sheet has a C++ options page. Here you can specify the 'Addional Include Directories' in a comma separated form.
Similarly, there should be a property sheet for Linker where you can specify the 'Addional Include Dependencies' and the names of the libraries it depends on.
For linker dependencies of the main executable:
Go to that main project, go to its properties, go to common properties and select 'Framework and References'. This should give you a list of all the projecs that are in your solution. Keep adding them and Visual Studio should add the right linker flags automatically for you.
Sorry, have no access to the computer now else would have provided exact steps. Visual Studio can get tricky sometimes but once you use it, you'll be amazed by what it can do for you. Personally, I love it.
Hope this helps.
Thanks to Vaibhav, I was able to find a solution:
I had to :
change subproject type to lib instead of exe
Add the subprojects as project dependencies in the main project (this just sets the build order)
Comment out the main of my subprojects, to keep only one active.
Add each subproject include directory in the include repos of the main project, so that the compiler can find the header files
Add the general directory as a dependency for the linker (in this case, it is not the debug/release folder of the subprojects, but the output directory of the complete project).
Add the names of the lib files of the subprojects in additional dependencies of the linker of the main project.
To make it simple, the project dependencies capability of VS2010 just changes the order in which the projects are built. . . I miss Eclipse.
If I find a bug and want to test on of the subprojects, I have to :
change the startup project to be the subproject I want to change.
uncomment the corresponding main
change the project type to be exe instead of lib to be able to compile it.
Debug, and do everything back again to continue working on my main project.
Quite boring, don't you think ?
Looks like you trying to do manual unit testing. Use something like Google.Test. You need to make test project for every lib.
We have directory with static libs projects. Another directory with tests projects. Every test solution contains one exe project and few existing lib projects. Every project have configured dependencies. You dont need to set additional dependencies of the linker manually (paths are evil, out dir for the lib file will be taken from project settings), open project properties with right mouse button, Common properties, Add new reference and select lib project. You only need to set additional include dirs.
When you find new bug - just open test project for the library with bug, add code which cause the bug, fix it, and be happy (and sometimes run all test). And even better - use TDD.

Is there a tool that allows you to custom build a vcproj?

We have several Visual Studio projects, and we would like to:
enable/disable some defines on some of the projects
add/remove include paths
change output directories ( lib dependencies ) for libs
In a nutshell, we would like to be able to support all of the things above, without having to have a lot of configurations in the solution file. Is there some tool which allows us to do that, perhaps from command-line, if VS doesn't support such a thing? We are using VS2005 Professional.
You can use property sheets to share build settings accross several projects. Projects can use multiple property sheets and property sheets can inherit from each other allowing you to mix and match however you need to.
In the build settings dialog for you project, you will need change the settings you are concerned about to <inherit from project defaults>. In this context, default means to take the value from the property sheet. Any default settings will appear non-bold, while settings that customized for the project are bold.
After that, you can change the values in the property sheets and have those changes applied to all the projects that use them at once.
You can use CMake to generate a VS .sln and .vcproj files.

Missing guiddef.h in project

I am new to Visual C++.
I am trying to use library A that in turn uses another library B. When I try to include the header of A, I get an "Error C2061: syntax error : identifier 'GUID'". This error is triggered in a header in library B. When I examine the line that throws the error, the issue is that the header in library B is using a definition found in Guiddef.h, which is a microsoft header.
The problem is that I can't seem to be able to add this header or to create a project that adds it.
I am using Visual Studio 2010 Premium.
Any ideas of what I am doing wrong?
Don't know what you mean by add it to a project or create one that adds it ,but when guiddef.h is on your system and your directories (in common properties) to your MSVC environment are correctly setup ,you just have to add #include <guiddef.h> before the including of lib-headerfiles to your cpp or h files and everything will (should) be fine.
guiddef.h is part of the Windows SDK. If you have VS 2010 Express the SDK is not included, you'll need to download it separately.
If you're using a VS SKU that's 'above' Express, the SDK should already be installed (I'm not sure if you can deselect it or not when in stalling). By default it'll go into:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\
The "Visual Studio Command Prompt" shortcuts that VS installs should set the INCLUDE environment variable appropriately. And a default C++ project should also have the include path setup appropriately, but it can be changed in the project's "VC++ Directories" property (you should check that). If you have a per-project setting here that is wrong, change it there.
However, if your 'IDE-wide' VC++ Directories properties that are inherited by every (or at least most) C++ projects is messed up, follow the instructions on this blog article to fix the global VC++ Directories settings in VS 2010:
http://blogs.msdn.com/b/vsproject/archive/2009/07/07/vc-directories.aspx
Specifically:
If you open up the Property Manager view to see the property sheets associated with your project, you’ll see that one of the property sheets is named Microsoft.Cpp.Win32.User. This property sheet is actually stored in LocalAppData, just as VCComponents.dat file was, in the directory %LocalAppData%\Microsoft\VisualStudio\10.0. Using the property editor on the property sheet (just right-click on this property sheet node and select Properties...), you can see that you are able to make edits directly to this file. Since all projects, by default, import this property sheet, you are effectively editing the VC++ directories in the same way you were able to do before.
It's possible (though not necessarily true) that you need to include a library as a linker dependency. I'm assuming here that you're already using #include (and have the correct case, with a lowercase 'g')
My suggestion:
Open up the project that has the
header included
open the 'project' menu, and select
'properties'
Under 'configuration properties'
select 'linker'
under 'linker' select 'input'
take a peek at the 'additional
dependencies' field (right at the
top on the right hand side). You
may see some libraries listed there.
Make a note of any libraries
included as dependencies, and repeat
these steps in your 'broken'
project. Add the appropriate libraries to the 'broken' project, if needeed.
You probably don't need the same dependencies in both projects, but if you do need to link a library in the borked project, you should be able to narrow down which one it is you need and include it in the dependency list.
Hope that helps, or at least doesn't steer you too far off course!
edit:
Actually, for some of the headers in the windows API, you might not be able to include them 'alone' (I'm not sure if guiddef.h is one of them), but they should be included as a sub-header of windows.h.