Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, October 28, 2017 12:41 PM | 1 vote
In the Property Pages of Visual studio 2015, I arrive Configuration Properties->Debugging->Environment window. I can set one environment like:
TESSDATA_PREFIX=.\tessdata
But when I use this sentence to set two environment in the meantime like this:
TESSDATA_PREFIX=.\tessdata;PATH=.\dll;%PATH%
The error information will tell me the latter variable is fail to set. Is is a bug of vs2015 or I have missed something?
ps: How to know the content of default value of $(LocalDebuggerEnvironment)?
All replies (6)
Monday, October 30, 2017 7:23 AM ✅Answered | 1 vote
Hi zhuyude,
Welcome to the MSDN forum.
Please have a look at this doc: Project Settings for a C++ Debug Configuration
Environment (Local Windows Debugger): Specifies environment variables for the program that you are debugging. Use standard environment variable syntax (for example, PATH="%SystemRoot%\.."). These variables override the system environment or are merged with the system environment, depending on the Merge Environment setting. When you click in the settings column, an "Edit…" appears. Click that link to edit environment variables.
I tried your sentence to set two environments and save it successfully as below:
But like RLWA32 and Darran Rowe said, it is better to separate two environments with 2 lines.
>> ps: How to know the content of default value of $(LocalDebuggerEnvironment)?
Click “Macros>>” button and there have no $(LocalDebuggerEnvironment), if the option “Inherit from parent or project defaults”, it should inherit from the system environment.
Best regards,
Sara
MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected]
Saturday, October 28, 2017 1:19 PM
The project properties work fine in my copy of VS2015 to set environment variables as above -
And the Macro listing did not contain any macro by the name $(LocalDebuggerEnvironment).
Saturday, October 28, 2017 1:38 PM | 1 vote
You missed something.
The for environment variables ; is used to separate values in a variable, so it can't be used to separate variables.
If you select the Environment option, a little button with a downward pointing arrow appears to the right hand side. If you click this you will get a dropdown menu with <Edit> and maybe <inherit from parent or project defaults> in there.
If you select Edit, then it will bring up a dialog which will allow you to enter the environment variables line by line.
This will correctly separate the environment. I think the environment needs to be separated using the null character which is why things were failing.
The default value of $(LocalDebuggerEnvironment) can be found by expanding the Macros section of this second dialog.
If you notice, in my list there isn't a $(LocalDebuggerEnvironment), this means it isn't set so it will expand to nothing. If it is set, then it will be shown in this list.
This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
Wednesday, November 1, 2017 2:34 AM
It's very useful to me, I just not understand that LocalDebuggerEnvironment Part. Could you tell me more about it? And I cannot search any useful information about it by google.
Wednesday, November 1, 2017 3:57 AM
The problem with TESSDATA_PREFIX=.\tessdata;PATH=.\dll;%PATH% is while it saves, it doesn't work like you expect.
Without editing it and setting it on two separate lines this will set the wrong value for the first environment variable and won't change the PATH environment at all.
The following program:
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <cstdio>
int wmain()
{
wchar_t envvar[500] = {};
GetEnvironmentVariableW(L"TESSDATA_PREFIX", envvar, 499);
wprintf(L"TESSDATA_PREFIX=%s\n", envvar);
GetEnvironmentVariableW(L"PATH", envvar, 499);
wprintf(L"PATH=%s\n", envvar);
return 0;
}
Gave me:
TESSDATA_PREFIX=.\tessdata;PATH=.\dll;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\C:\Program Files (x86)\Skype\Phone\C:\Users\Darran\AppData\Local\Programs\Python\Launcher\C:\Users\Darran\AppData\Local\Microsoft\WindowsApps;
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\C:\Program Files (x86)\Skype\Phone\C:\Users\Darran\AppData\Local\Programs\Python\Launcher\C:\Users\Darran\AppData\Local\Microsoft\WindowsApps;
As output on my system. Having the ;PATH=... as part of the TESSDATA_PREFIX is not what the OP wanted. However, if we use the edit and separate it onto two lines, the output of the same program is:
TESSDATA_PREFIX=.\tessdata
PATH=.\dll;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\C:\Program Files (x86)\Skype\Phone\C:\Users\Darran\AppData\Local\Programs\Python\Launcher\C:\Users\Darran\AppData\Local\Microsoft\WindowsApps;
Which is what I assumed the OP wanted. This is why RLWA32 and I suggested using the Edit option exclusively.
This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
Wednesday, November 1, 2017 4:12 AM | 1 vote
Variables like $(IncludePath) and $(LibraryPath) are how you would inherit the original value of that setting when you override it.
This is because the build settings for VC projects are really just a bunch of property sheets that the build system evaluates in order. If you open up the Property Manager window in Visual Studio then you will see all possible configurations of your project, which you can expand to see the property sheets used.
The majority of the ones added by default are read only. When the build system starts reading these, it starts with the very bottom one for the configuration, Core Windows Libraries, it then goes to the next one up and changes any settings that the next one up defines, and it keeps going up until it gets to Microsoft.Cpp.<platform>.user. The top of this list is your project itself.
So if you want to modify a value such as the Include Directories property in your project, then you could edit the Include Directories property to something like $(SolutionDir)MyIncludes\$(IncludePath) and the $(IncludePath) macro would expand to what was defined in the lower level property sheets. This way you can add to the paths but not lose the original settings.
$(LocalDebuggerEnvironment) also serves this same role. It could be used to access the environment set for the Local Windows Debugger at a lower level property sheet. The thing with this is that the project is the only place that the debugger settings are defined, so it will always be empty.
This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.