C ++ - using environment variable in property sheet for Visual Studio 2010

I want to create a project that uses OpenCV. So basically, I have to add a new property page using the property manager from Visual Studio 2010.

Basically, I have to add the path to my include and lib folders to make OpenCV functional. I want to put my project in the git repository, and I don't want to change the paths in my property sheets every time. Is there a way to use the system variable in my properties page with the path to the OpenCV build folder? If there is a way to do this, can I assign a value to this variable directly from the code? Like a #define or similar assignment?

+2
c ++ environment-variables visual-studio-2010 opencv
source share
2 answers

You can use many useful macros / properties to build paths that relate to the location of your project, solutions like $ (SolutionPath), etc. (They are listed when editing a text field in the configuration.

The usual place to define a machine, installation, or user material is the users.props file (Microsoft.cpp..users.props) located in the $ (USERPROFILE) \ appdata \ local \ microsoft \ msbuild \ v4.0 directory.

If you open .vcxproj, you can see that it is turned on close to the top. Use it to define some basic directory paths as properties, and later you can use those that were built-in. Of course, you can also use this to find the .props file and import it.

Or you can use it to add additional entries to include an element directly.

+2
source share

The "macros" available in the property settings are actually environment variables added by Visual Studio. If you set the environment variable in your user profile, you can add it to your property sheet in the same way as you use the "built-in" VS macros.

For example, I have a network hard drive with a folder named LIBS containing Boost, Google Test, Google Mock, Tiny XML, and several dozen other libraries. I mount it as the drive letter Z , and I have an environment variable set in my user profile named XTPLIBRARIES that points to Z:\LIBS . In my properties page, I have configured inclusion paths as shown below.

$ (XTPLIBRARIES) \ boost_1_53_0 \ boost
$ (XTPLIBRARIES) \ GTEST-1.6.0 \ include
$ (XTPLIBRARIES) \ tinyxml2

Now, when I create a new project, I just add a property sheet, and everything works as expected, until the environment variable is set, of course.

+2
source share

All Articles