PATH Environment Variable has no Effect? (VS2010) - c++

From what I can tell from this MSDN walkthrough, the PATH environment variable should point to the location of a DLL when the DLL isn't in the same directory as the source.
I have set this variable through Property Pages > Configuration Properties > VC++ Directories > Executable Directories (which does correspond to the PATH variable, according to the tooltip).
When I try to compile and run my code, however, I still get "missing DLL" errors. Manually copying the DLL into the source folder solves the problem, but that's not really an option in this case.
What am I missing here?

The PATH directory that the "Executable Directories" page refers to are the directories that are searched for compiling your code, not the directories that are searched at run time to execute your program.
If you don't want to set your path every time in your command prompt, you can update your PATH environment variable for your user session. (My Computer -> Properties -> Advanced -> Environment Variables) You can then either update your system PATH variable or create a local PATH variable for your user account. (Make sure you restart your command prompt after you do this)

Related

why std::filesystem::current_path() returns different variables when im in editor and using .exe

I have my project where i am using filesystem to retrieve directory of assets.
When i am lunching my program in editor(im using Visual Studio 2019) everything is fine and this code return value of working direcotry of project.
std::string currentPath = std::filesystem::current_path().string();
But when i am lunching app from .exe file this line of code returns path that leads to .exe file.
The same directory called $TargetPath in properties in VS.
So my question is why is that happening and how can i resolve this problem.Becouse of that i cannot automatically load assets when lounching app from .exe file
Because it gives the current working directory, which is set by the environment calling your program (unless your program explicitly changes it).
So, it does what it's designed to do, gives the current working directory:
Returns the absolute path of the current working directory,
So my question is why is that happening
It happens because you've configured the editor to set the working directory to one path, while you're running the program with another working directory outside the editor.
how can i resolve this problem.Becouse of that i cannot automatically load assets when lounching app from .exe file
Here is an approach:
Store the assets in a path that is relative to the exe.
Get path to the exe.
On POSIX, you can use argv[0] from arguments of main
On Windows, the documentation recommends GetModuleFileNameW
Get canonical absolute form of that path (make sure that working directory hasn't been changed before this step if the path to exe is relative).
Get the directory that contains the exe from that canonical path.
Join that directory path with the asset's relative path to get an absolute path to the asset
Load the asset using the absolute path.

How to debug Visual Studio environment variable usage?

I am unable to change my PATH environment variable from Microsoft Visual C++ 2010 Express using a project relative path.
Relevant paths:
Solution path: D:\School\dva303\project\Woods\
Project path: D:\School\dva303\project\Woods\Woods\
Absolute path to needed DLL directory: D:\School\dva303\project\Woods\Woods\allegro-5.0.10-msvc-11.0\bin
When I use the absolute path:
Project Properties / Debugging / Environment: PATH=D:\School\dva303\project\Woods\Woods\allegro-5.0.10-msvc-11.0\bin
It works! But if I change it to a project relative one using $(ProjectDir):
Project Properties / Debugging / Environment: PATH=$(ProjectDir)\allegro-5.0.10-msvc-11.0\bin
It fails and I get a message that the DLL can not be found on my computer. It does not matter if I use a \ after $(ProjectDir) or not.
Questions:
How do I get it to work?
How do you debug situations like this one when a Visual Studio environment variable is not behaving as you expect it to? Is there a way to print it out or by some other method see what it will be evaluated to?
You can simply add a post build task to echo out $(var), and you'll see it in the output window.
I think your actual problem is that your environment variables don't propagate to the application you run/debug. You can use SysInternals' Process Explorer to check this. If so, just add another post build task to copy the required DLL files to the same directory as your output.
If you just want to see the values of $(ProjectDir) then if you go in to your vcxproj properties, then anything then lets you get to the "macros" view. Such as adding a new include path will list these out and their values. But you'll still need the echo trick for anything "dynamic" or to check nothing is overriding it.

Eclipse CDT Can't Find include file unless full relative path is used

I've been using Eclipse for a while and this has me stymied. I created a library name ITS8410_LIB a few weeks ago and then let it sit while I worked on a supporting library called Reach_Lib. The directory include paths I added back when I first created the project work fine. Today I finished Reach_Lib and went to add its path to ITS8410_Lib. I used the project properties C++ settings to add a workspace path (like I've done many times before). I have only one build configuration. The path is shown in the image (the one highlighted in blue is the specific one I'm talking about in this question).
When I go to include the file in the source neither Eclipse (I see the yellow question mark) nor the compiler (I get a compiler error) can locate the file. If I add the a directory path using the full absolute path syntax the results are the same. I can modify the source code and specify the #include via a full relative path from the current directory, and it is found. Eclipse just won't use the path specified in the project settings. This same Reach_Lib has an associated unit test project and the path is specified with a workspace setting from there and it works fine.
Directory paths that were added before today appear fine. Paths (there are two libs showing this behavior) I add today just seem to be ignored. I took a look at the compiler settings (see image below) and the path specified to the compiler appears to be OK.
Running under Windows7 64 bit (but using a 32 bit version of Eclipse Indigo).
I have tried:
rebuilding indices
Exiting and restarting Eclipse multiple times
workspace and absolute file paths
modifying the order of the include paths
different .h include files in project
Update
I took a look into the .cproject file and while I don't know much about what these files are supposed to look like I think I have a problem. Maybe the question is: How do I tell Eclipse to rebuild the .cproject file? I appear to have two similar sections and Eclipse is getting confused. I can see different version numbers tagged as suffixes. It appears to me that the visual editors are letting me modify one section but the IDE and compiler only care about the other section. Here's the relevant portions
...
<folderInfo id="nbeclipse.toolchain.nbl.rel.396284009." name="/" resourcePath="">
<toolChain id="nbeclipse.toolchain.nbl.rel.tc.1465290409" name="NetBurner Device Library" superClass="nbeclipse.toolchain.nbl.rel.tc">
<targetPlatform id="nbeclipse.toolchain.nbl.rel.tc.targetPlatform.283367649" isAbstract="false" name="NetBurner Module Library" superClass="nbeclipse.toolchain.nbl.rel.tc.targetPlatform"/>
<builder buildPath="${workspace_loc:/ITS8410_Lib/Release}" id="nbeclipse.toolchain.nbl.rel.tc.builder.2064025940" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Release ELF builder (MINGW)" superClass="nbeclipse.toolchain.nbl.rel.tc.builder"/>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gcc.278195048" name="GNU C Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc">
<inputType id="nbeclipse.toolchain.nbl.rel.tc.gcc.input.1060035859" name="GNU C Input" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.input"/>
</tool>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gpp.767008127" name="GNU C++ Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gpp">
<option id="nbeclipse.toolchain.super.gcc.directories.includepaths.1666029541" name="Include paths (-I)" superClass="nbeclipse.toolchain.super.gcc.directories.includepaths" valueType="includePath">
**inside here is an option list with all my include paths**
...
</folderInfo>
Then right after the folderInfo close tag another folderInfo section starts
<folderInfo id="nbeclipse.toolchain.nbl.rel.396284009.2022231003" name="/" resourcePath="src">
<toolChain id="nbeclipse.toolchain.nbl.rel.tc.1982112905" name="NetBurner Device Library" superClass="nbeclipse.toolchain.nbl.rel.tc" unusedChildren="">
<targetPlatform id="nbeclipse.toolchain.nbl.rel.tc.targetPlatform" isAbstract="false" name="NetBurner Module Library" superClass="nbeclipse.toolchain.nbl.rel.tc.targetPlatform"/>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gcc.1671008421" name="GNU C Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.278195048">
<inputType id="nbeclipse.toolchain.nbl.rel.tc.gcc.input.436341699" name="GNU C Input" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.input"/>
</tool>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gpp.498310867" name="GNU C++ Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gpp.767008127">
**the newly added paths don't show up here, if I add them manually things start working**
The key to the answer was posted by dbrank0 but he didn't promote it to an answer so I just upvoted the comment. Something went wrong in the .cproject file and editing it manually fixed the problem.
Try to replace relative workspace path to real path (add same include as filesystem) in include directories project settings.
full absolute path is okay at any time.
when use the relative directory you should be careful.
in eclipse the current directory is not the same as run directory.
string strRunDir, strCurDir;
strRunDir = AfxGetApp()->m_pszExeName;
strCurDir = GetCurrentDirectory(...);
and strRunDir != strCurDir;
when you want to use the relative directory, you should reference to the runDir;

Include path not expanding when using path variable

I create a new c++ project. Then right click on the project -> properties -> Resources -> Linked resources, where I defined a path variable :
MY_PROJ_ROOT <some_correct_path>
Then I went to compiler options -> Include options, where I tried to add include path combined with the path variable like this :
"${MY_PROJ_ROOT}/include"
but the include directory is not shown in the Include tab under the project menu. Instead of showing full include path (like for other includes), I get only this : /include.
So, am I doing something wrong when using path variable to set include? What is the correct way?
PS I checked paths, and everything I could think of, but nothing worked.
Finally I figured out :
Open project properties -> C/C++ Build -> Build Variables tab, and add new variables :
MY_PROJ_ROOT <some_correct_path>
Then the variable is going to work for the includes tab.
Try ${env_var:MY_PROJ_ROOT}. Eclipse comes with its own schema for inserting variables. If there should be a button "Variables...", click it and you will see the various options, of which one is env_var that takes an environment variable name as argument. In fact, you may want to use ${project_loc} instead of defining your own variable.

Where can I set path to make.exe on Windows?

When I try run make from cmd-console on Windows, it runs Turbo Delphi's make.exe but I need MSYS's make.exe. There is no mention about Turbo Delphi in %path% variable, maybe I can change it to MSYS in registry?
The path is in the registry but usually you edit through this interface:
Go to Control Panel -> System -> System settings -> Environment Variables.
Scroll down in system variables until you find PATH.
Click edit and change accordingly.
BE SURE to include a semicolon at the end of the previous as that is the delimiter, i.e. c:\path;c:\path2
Launch a new console for the settings to take effect.
Here I'm providing solution to setup Terraform environment variable in windows for beginners.
Download the terraform ZIP file from Terraform site.
Extract the .exe from the ZIP file to a folder eg C:\Apps\Terraform
copy this path location like C:\Apps\terraform\
Add the folder location to your PATH variable, eg: Control Panel -> System -> System settings -> Environment Variables
In System Variables, select Path > edit > new > Enter the location of the Terraform .exe, eg C:\Apps\Terraform then click OK
Open a new CMD/PowerShell and the Terraform command should work
Or you can just run this PowerShell command to append extra folder to the existing path:
$env:Path += ";C:\temp\terraform"
To add a PERSISTENT path (eg one that's permanent), you can do this one-liner in PowerShell (adjust the last c:\apps\terraform part)
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value (((Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path) + ";c:\apps\terraform" )
Alternatively, you can jump directly to the Environment Variables dialog by RUNning/CMD/PowerShell this:
rundll32.exe sysdm.cpl,EditEnvironmentVariables
I had issues for a whilst not getting Terraform commands to run unless I was in the directory of the exe, even though I set the path correctly.
For anyone else finding this issue, I fixed it by moving the environment variable higher than others!
Why don't you create a bat file makedos.bat containing the following line?
c:\DOS\make.exe %1 %2 %5
and put it in C:\DOS (or C:\Windowsè or make sure that it is in your %path%)
You can run from cmd, SET and it displays all environment variables, including PATH.
In registry you can find environment variables under:
HKEY_CURRENT_USER\Environment
HKEY_CURRENT_USER\Volatile Environment
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment
just copy it to system32 call make1 or whatever if the name conflicts.