Netbeans/C++ add environment variable at make - c++

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.

Related

Eclipse ignore LD_LIBRARY_PATH in Environment

I'm trying to lunch an application from Eclipse CDT and as I read everywhere, I set LD_LIBRARY_PATH to the directory containing the shared library:
However, when I try to run this configuration:
/home/luca/Dropbox/HKUST/CloudCache/cloudcache/CloudCache/make/CloudCache: error while loading shared libraries: libvl.so: cannot open shared object file: No such file or directory
Just to clarify: I'm 100% sure that libvl.so is in that path, in fact when I try to run the application from command line it works perfectly.
Why this happens?
I wonder if it is being reset somewhere else. You can also set environment variable in the Launch Configuration if you are using that. There are two places in there, one where you have an 'Environment' tab, and another where you choose your 'Build Configuration' which could itself point somewhere else.
I've just been trying to get this to work for the first time in eclipse (Linux 64), and did exactly what you showed and it worked.
A bit late, but still can be useful. You have the option "Append environment to native environment" checked on your screenshot. Very probably you have this variable redefined there. It was my case.

Permanently storing an environment variable when using CMake install

I'm trying to store a path environment variable to the location of some configuration files my program needs at runtime, but I do not know the location of until the compiled program is installed.
My idea was to use the following:
install(CODE "set(ENV{MY_CONFIG_PATH} \"${CMAKE_INSTALL_PREFIX}/MyConfig\"")
However, I quickly found out that this does not permanently set that environment variable so as soon as I run the program and check the contents of MY_CONFIG_PATH with std::getenv(), I get a null pointer.
I thought about maybe setting a preprocessor define at compile time, but that won't work either because it seems CMAKE_INSTALL_PREFIX is only populated when the installation process is executing.
Can anyone suggest a neat workaround that works for both Windows and Unix?
Since CMAKE_INSTALL_PREFIX is known at configure-time you can use the configure_file command to configure a file and insert the value of CMAKE_INSTALL_PREFIX into the specified location.

Can't change system variable "Path" for netbeans

I downloaded Netbeans because I wanted to start learning C++. I downloaded the compiler, debugger, and make utility from cygwin. In order to complete the process of setting up my IDE I need to modify the system variable Path to reflect my new cygwin installation.
So here is what I do:
type var into windows search
click on Path in the system variables
Here is where the issue arises. The instructions I am reading tell me to edit the Path variable, but the buttons are unclickable. They remain faded even after clicking Path. When I double click the Path variable I hear the windows "error" chime.
I don't know why I can't modify the Path system variable. I have ensured that my account (the only one on the computer) is an administrator. I am running windows 7 if that makes a difference.
Thanks,
Alex
I solved it just now. Even though the end destination is the same, typing var into the search bar opens the environment variable window, but prevents editing. However, if you right click Computer, select properties, select advanced settings, then click on environment variables, even though you're in the same location, the variables are then editable.

Why does not Visual Studio 2010 "unpack" system variable?

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.

How can I set environment variables PATH and LD_LIBRARY_PATH on Unix TeamCity build agent?

I use TeamCity to build c++ on Unix (Solaris). TeamCity invokes make, and within my makefile I need to call svn. For this I need to modify PATH and LD_LIBRARY_PATH.
I could set these within the makefile but the locations vary from server to server. does anyone know a way to set these for each TeamCity build agent, e.g. by editing conf/buildAgent.properties?
I could set them in ~/.login etc for the TeamCity build account, but I would prefer not to as it is a shared account.
-thanks, Barney
You can configure the environment in conf/buildAgent.properties as you suspected, by setting properties that begin with env.. It works for both setting variables from scratch and modifying existing values. Mine looks like this:
env.MAKEFLAGS=-j8
env.PATH=/usr/local/bin:%env.PATH%
(It's hidden in the docs. I'm not sure if 5.0 had this (I think it did, though), but 7.0 definitely does.)
You could create a wrapper script that exports these variables before executing the TeamCity command.