Why does not Visual Studio 2010 "unpack" system variable? - c++

I was trying to set up an Ogre3D application and I set an "OGRE_HOME" system variable to the home directory of the SDK. Then I set project properties, like include directories in the Project Properties, using the $(OGRE_HOME) system variable. But when I tried to compile the application, the compiler did not find the header files, so I had to "hardcode" the SDK path to the project properties.
I set the variable first with the setx command, then I tried moving it to system variables but it did not help. However I did not try to reboot the system.

MSBuild does expand environment variables. $(OGRE_HOME) should work just fine.
The only problem is that Visual Studio caches the values of these environment variables heavily, so changes that you make will not be immediately reflected.
There are two general ways to change the values of environment variables, and both of these go wrong with VS:
Changing the values from the command line only affects applications that are launched from the command line. Since you're probably launching VS from a shortcut through Explorer, it won't inherit the new values.
Changing the values through Computer Properties should normally work because that dialog broadcasts a global message indicating the persistent environment variables have changed. Unfortunately, VS doesn't seem to listen to these messages and update its cache.
But, restarting (or logging off and back on) should fix the problem, as this will cause VS to refresh the values of the environment variables.
It's also worth noting that user macros are an alternative to environment variables. VS 2010 provides a very robust way of implementing these through the Property Manager. You can create a project property sheet with your settings, which can then be attached to multiple projects so that they will all inherit these settings. It doesn't work outside of VS, but it can be quite convenient if you do all of your development work there.

Related

Netbeans/C++ add environment variable at make

I need to set a variable that is checked in the makefile(i.e. at compile time), but I can't find it in the project properties.
I right-click on the project, but can't find a place to set environment vars, except in the Run but even there it seems I can't add a variable (nothing happens when I click on Add after expanding the ...).
What am I missing?
As a side: Netbeans probably will run a shell before issuing the commands like make, what kind of shell is it? how can I configure it?
Judging by your screenshot that you are on OSX, you should be able to set an environment variable by replacing "${OUTPUT_PATH}" under Run Directory with FOO=BAR;"${OUTPUT_PATH}". This is normal POSIX syntax for running a program with a specific environment variable or set of variables set, and can be used at the terminal as well.
Edit: In Netbeans, to set an environment variable for a specific action, right click on project, go to Properties->Actions->{Action}->Set Properties: Add Env.FOO=BAR.

Visual Studio 2010 default property sheets seem linked under both debug and release configurations, what's up?

I'm trying to alter the default property sheet on a new install of Visual Studio 2010 for C++ projects. Just trying to add a few directories (for Boost etc.) and optimisation settings for release builds, basic stuff like that. Obviously there are some settings that I want to be different for different configurations. Problem is that whatever I try from the property manager window of my project, everything I do seems to affect both configurations.
I tried multi-selecting both -> right click -> properties initially, to set up common settings, and that did exactly the same thing as selecting Microsoft.Cpp.Win32.User under either debug or release. So everything affects both configs.
Now, as I understand it, Microsoft.Cpp.Win32... is a single file (at least, a single file for x86 configs, single file for x64 etc.) so the fact that I can't change the configs individually actually makes some degree of sense. But if I can't do it that way, how can I do it?
Appreciate any advice!
Short answer: you can't. See comment discussion under question.

How to organize dependencies in Visual Studio 2010 C++ best?

I am new to Visual Stuido and I want to know how to organize the dependencies of a project in Visual Studio 2010 C++ (Express Edition) best.
The main problem is the following:
A project P requires lib L, so I add dependecy L to P. L is somewhere located at my system. I submit P to our version control. My colleague checks P out, but the configuration of P does not fit to his system (L is located somewhere else at his system). So he adjusts the configuration and submits the changes to P. I check P out and now it does not fit to my system.
I come from Java and Eclipse. In Eclipse you can set a variable globally for the whole IDE f.e. PATH_TO_L. In the project configuration the dependency is now variable PATH_TO_L and not anymore a path. So my colleague and I can use the exact same sources including the project configuration. All we have to do is to set both the variable PATH_TO_L. Nice.
Even nicer is Maven. So you do not have to care about copying the right dependencies to the right locations, because Maven does all the work for you.
I searched a little bit for a solution. One possible solution would be to use Property Sheets and to add a template Property Sheet to our version control. But templates in version control are not comfortable to use and I would have to adjust the settings for every project. Not a global setting.
I tried to use system environment variables, but I think Visual Studio 2010 does not use them.
So here is the question. How do you organize your projects in Visual Studio 2010? Is there an ideal way? Is there something like Maven, or is there a possibilty to use an repository manager like nexus in Visual Studio?
You are on the right track, with the property sheets.
You could use a property sheet to reference a environment variable. An example is here.
I would add the Path of library to the user specific property file named Microsoft.Cpp.<platform>.user. As this is included by default. More information is here.
As soon as you get familiar with the property sheets it not as bad as it seems. I actually start to like the msbuild system. But I am not aware of anything like maven for msbuild.
Quite a lot of people are using meta-build systems, these days, such as CMake, SCons...
Amongst other useful features, you can set up some variables that you can later reuse, for example for paths. This way, your colleague and yourself will have the same CMake configuration, but with individualised paths.
And, as these scripts are simple text files, they play nicely with version control (much better than MSVC xml configuration)

OSX env variables for c++ development

With visual studio there is an start menu option open a terminal window with all of the paths and environment variables setup to use the compiler.
Is there an equivalent for XCode or is there somewhere I find out what needs setting for this to work?
I am trying to get the boost libraries compiled but am just getting a tone of errors related to simple stuff. I have set some some of what I think should b required (include and lib paths) but I am obviously still missing some.
Martin
Xcode uses gcc and llvm-clang. So the environment variables settings are the same as those.
But if all you want is to have boost available to your project, it may be easier to just install MacPort and build/install boost with it: http://www.macports.org/ports.php?by=name&substr=boost
MacPort supports many, many, many tools and libraries. It will make your life developing on OS X a lot easier.
It sounds like you're really asking about build settings -- the variables that are available at compile time to define things like paths and options. You can set these on a per-project or per-target basis in the Build Settings pane. Select either your project or one of its targets and click on Build Settings. If you want to define your own settings, scroll to the bottom of that pane and look for the "User-Defined" section, where you can add your own settings.
If you want to set environment variables (and arguments) that will be in effect when your program is running, hold down the Option key and choose Product->Run..., at which point you'll get a window that allows you to define environment variables and arguments.

How to setup directories in Visual Studio when using boost?

I have introduced boost to our code base, on my machine I created a boost directory called Thirdparty.Boost and added that as an additional include directory in my Visual Studio setting, all is fine.
However I now want to check in my changes, so the rest of the team can get them. Inorder to build the code they would need to setup boost as I have (problem number 1). In addition we have a build server, which will need changing (problem 2). I have a way of distributing boost to everyone including the build server, so that's not a problem
I need a way of referring to the boost directory without changing the default settings in Visual Studio. Why don't you change it on a project level I hear you cry? The solution has over 200 projects, which would require a lot of changes.
I just wondered if there was another way?
Cheers
Rich
What about adding an environment variable on each of your developer's machines:
CL=-I<...the_boost_directory...>
i.e. on your machine:
CL=-IThirdparty.Boost
The MS compiler adds the value of the environment variable CL to its command line, so this should do the trick for you.