Environment variables in Visual Studio 2013 - c++

I'm trying to set my project include to the path %OPENCV_246%\..\..\include
This resolves to the path F:\dev\opencv_246\build\include
However, when setting the project includes, that path will not resolve and as a result the included headers break.
I've tried both %OPENCV_246%\..\..\include and $(OPENCV_246)\..\..\include with no luck.
Using the path directly fixes my includes, but I'd like to have a better way of managing the path through environment variables.
In the screenshot I've added both for clarity, If anyone could point out the step I'm missing here I'd appreciate it.
EDIT: Variable OPENCV_246 contains value F:\dev\opencv_246\build\x86\vc11

Dev studio won't recognize any environment variables that have been changed since it was started, so if you change one, a restart is required (of Dev studio, not the computer).
https://superuser.com/questions/107521/why-are-changes-to-my-path-not-being-recognised

This sounded similar to my problem, which was getting VS2013 to acknowledge a change I made to my environment variable (in my case QTDIR). Even after a restart and a shutdown, it obstinately hung on to the old value !! (you can see the value if you go to edit a project setting, hit the "Macros" button, and scroll down the list to find e.g. "$(QTDIR)" )
Here it suggest VS2010 cahed values heavily, but 2013 seems even more keen !
After some FindInFiles for the old path, it seems that VS2013 caches environment variables in your .vcxproj.user file. I have no idea how it got in there in the first place.
So I deleted the entry, closed the solution, checked the file again in WordPad to make sure the entry hadn't been put back in. Then I re-opened the solution, but the old value was still there in the Macros list !
Closing VS seems to have done the trick. Now it seems to have the right path - although I'm sure I checked after I first opened the solution and QTDIR wasn't in the Macros list at all - maybe I'm confused...
Well, it all seems to be working now, and my project builds and links to my Qt libs without complaints :-)
And, the entry in the vcxproj.user file hasn't come back. So I still don't know how it got in there. Maybe I did something to cause it a while back in a previous version of VS...

Related

How to change default location for *.db?

I'm using the new Visual Studio 2017. I follow this tutorial to change the default (temp) path where store .db and such.
It correctly moves *.VC.db files, but I can still see these files into the .vs within the solution's folder:
Solution.VC.db
Solution.VC.db-shm
Solution.VC.db-wal
I'd like to also move these data. How can I do it?
The guide that is the source of all these tutorials and advices is https://blogs.msdn.microsoft.com/vcblog/2010/03/09/intellisensebrowsing-options-in-vc-2010/
You are trying to get rid from you *.db files in {ProjectDir}/.vs/{SolutionName}/v15{(VS version)}/ and following the old guide for ipch files
you successfully moved Browse.VC.db fie. However
Solution.VC.db
Solution.VC.db-shm
Solution.VC.db-wal
Are not browsing files and have nothing to with Intellisense. They are
Project Preload files and needed only to speed up VS hefty loading of solutions.
The answer to your question: No, you can not move them to the other folder by the means of VS options. They are supposed to be internal matter of VS speeding up the openage.
2 of this 3 files should disappear when you close the solution( the heaviest one will remain)
However there is a lot you can do about it:
1)You can turn them off completely by Tools->Options->Text Editor->C/C++->Experimental in Enable Faster Project Load = False
2) If you'd like to leave project load(I don't feel much difference, but maybe I don't have very big projects) you can always clean files ad hoc by Project->Properties->Build Event->Post Build and entering any console command you'd like removing files from that folder- that will happen each build, which is what you want in the end when you close it.
3) You can hack their size to zero by using symlinks - just create symlink with the same name(by a script, maybe) that to points to the location you like and VS won't spot the difference.
Also, you can turn off browsing db in the Advanced - it will turn off Intellisense (or leave where you moved it).
I hope it helps to solve this issue with heavy untransportable files.
Two things
how to control or manage the path where .vs folder is created?
Currently I couldn't find a way for this - its still created next to solution folder (I am using VS 2019)
how to control or manage the path where the contents (like Browse.VC.db and including the other temp ones like Browse.VC.db-shm, Browse.VC.db-wal & Browse.VC.opendb) are created?
Solution: Use Fallback Location
Visual Studio > Tools > Options > Text Editor > C/C++ > Advanced > Browsing Database Fallback > "Always Use Fallback Location" as true and provide a valid path to "Fallback Location".
After this, I have to restart VS.
This is especially useful when you are using cloud or web drive for your solutions and / or projects and don't want these temp files to clutter and consume more spaces.

The desired name for <file> is invalid - visual studio 2015

This is pretty crazy, I am only adding an existing .h file to VS2015 C++ project but it would complain:
The desired name for c:\code\usbview\USBdevices.h is invalid
I was able to add this file to project when it had its own .sln file. However, I created a new empty .sln file and wanted to add this and other project and that's how this issue kicked in. It wouldn't add this project to new solution giving a similar weird error about the files I added.
I then add the base project to that solution file and tried to add this .h and .cpp files there but it adds the .cpp but gives this error for .h file.
This is very weird, I changed the files names but the same error.
The link in the comment section by BlackDwarf fixed the problem even though that was was for C# but applies.
I didn't have USERPROFILE environment variable so I created it and set it to c:\Users\my.name and now I can add the file
I had the same problem and it was because of merge errors in the file ProjectName.vcxproj.filters.
The answers here led me to check my vcxproj when I experienced the OP's problem.
It turns out I had two filters with the same name in my Project.vcxproj.filters, something like
<Project>
<Common>
...
...
<Stuff>
<Common>
And I was trying to add files to the second Common.
To fix it, I had to ..
edit the vcxproj manually in {favoured text editor} and remove the second filter I'd added with a duplicate name.
Unload/Reload the project from the solution in VS(2017), and add a filter with a unique name. All good - I can add files to my new filter.
I use VS 2013 Express and had the same error.
Solved by removing VCTargetsPath environment variable, I added it some time ago, don't remember why :)
I had the same issue, but the solution had nothing to do with "Environment Variables" for me. What I did: Close Visual Studio 2017. Reopen my project. Suddenly I had two copies of the "Helper.cpp" and "Helper.h" that I was trying to add already as part of the solution files. Clicking on each I saw that one of the files was invalid, probably because I had deleted that version of the file in that file location. I deleted the invalid files, checked to make sure that the files had the correct code I wanted in them, built the solution and everything ran fine.
Not sure why closing and reopening VS fixed the problem, but glad it did.
If the environment variable route doesn't work for you, check the integrity of your project file next.
I had this problem in 2017, and it was due to a double entry in the vcxproj from a manual editing error. Our vcxproj file had the following in it:
<ClInclude Include="XXXX.h" />
<ClCompile Include="XXXX.h" />
In 2017 we got exactly the error you described when trying to add an existing file, a slightly different one when adding new, and strange crashes elsewhere. Opening the solution in 2015 logged the exact problem and failed to load the project. We removed the double entry and all the mysterious problems vanished.

Global include path on Windows on VS2013

I should add a global include path to my system (i.e. it's Google Test so I need to include "C:\gtest\include")
I appended it to the PATH environment variable and restarted VS2013. However, VS2013 still complains about the missing .h files.
What's wrong with this IDE?!?
First, you definitely don't want the PATH environment variable. You do want the INCLUDE environment variable.
Second, use a statement like SET INCLUDE=C:\gtest\include;%INCLUDE% to set it.
Third, that's only going to work in a command window that you're running command line builds in.
Fourth, so try setting it on your machine using This PC's properties "Advanced System Settings" Environment Variables dialog. Remember to restart your VS2013 after setting it so it picks up the new env vars.
Fifth, why not do a SET (with no arguments) after you've set your non-working INCLUDE variable and paste the result into your question so we can all see what your environment variables look like - then we might be able to help you better.
Sixth, it's going to end up being your misunderstanding of how things work. That's clear since you think the PATH env var has something to do with VC++ searching for include files. So why the gratuitous "What's wrong with this IDE?!?" slam? It's not winning you any friends.
Seventh, see the MSDN article Setting the Path and Environment Variables for Command-Line Builds for tips. It came right up when I googled for "visual studio include environment variable", and it has help for you.

vs10 C++ $(MyLibrary) vs %(MyLibrary)

We are using an environment variable to specify a path to a library we use. Most of the time it points to the released version but sometimes to a development version.
Anyway, it works ok when I use $(MyLib)/path;%(AdditionalIncludeDirectories) for building the C++ application but I can not open the project resources. However, when I use %(MyLib)/path;%(AdditionalIncludeDirectories) it works.
Now, what is the difference?
I thought the correct way is to use $(EnvVar) but for the resource editor it doesn't seems to work. And if $(EnvVar) is the correct way then why does Visual Studio use %(AdditionalIncludeDirectories) and not $(AdditionalIncludeDirectories)
The error I get is: fatal error RC1015: cannot open include file 'afxres.h'.
You use %(item) to refer to an MSBuild metadata item. Using $(AdditionalIncludeDirectories) would not work well if you also had an environment variable by that name. So %(MyLib)/path ought to resolve to just /path.
You can put echo %(MyLib)/path in a prebuild event to verify this.
Which is probably enough to stop confusing rc.exe, the resource compiler. Which is a stone-cold-old SDK utility, going back all the way to Windows version 1.0. It is pretty temperamental, very picky about command line options and .rc script file text encoding. Do keep in mind that it dates from an era long before Windows started to support a forward slash as a path separator, everybody had to use a backslash back in 1986.
So use "$(MyLib)\path" instead, including the double quotes so you don't confuzzle it when MyLib contains embedded spaces. And do favor using a project property sheet instead so there are some odds that somebody can still figure out how to get the project built correctly 2+ years from now.

WxWidgets - Unable to load images

I recently started working with WxWidgets (2.9.4) and was working through a tutorial I found, but it seems that I'm unable to load any images. I've already properly used the handler (for PNG) and the problem happens at run-time. Below is an image of the popup that is displayed when attempting to run the program.
Here is the code:
wxPNGHandler *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxBitmap exit;
exit.LoadFile(wxT("exit.png"), wxBITMAP_TYPE_PNG);
wxToolBar *toolbar = CreateToolBar();
toolbar->AddTool(wxID_EXIT, exit, wxT("Exit"));
toolbar->Realize();
Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(mainWindow::exitProg));
Any help is appreciated.
EDIT: I forgot to mention that when I click Cancel, this happens:
I placed the exit.png file in the build directory (/Debug or /Release) as well as the source code directory, but it still has yet to see it.
What is your working directory?
If you are using visual studio and running using the interface ( F5 or ctrl-F5 or the little run button in the toolbar ) then your working directory is the folder containing the project file. So try copying your image file there.
Or open a command window, cd to one of your build directories, and run your app from the command line.
In general, to avoid this sort of problem, I alter the project properties so that the executable is NOT stored in one of the build folders, but in a new folder ( which I usually call 'bin' - my unix roots are showing! ) and also alter the debugging properties so that the working directory is the bin folder.
There are a couple of advantages to this technique:
Both the release and trhe debug version use the same folder, so you only need one copy of any extra file, like your image file.
It is easy to see the executable and extra files in the working directory without being distracted by all the .obj files that end up in the build folders
IMHO this is well worth the little extra trouble in maintaining non default project properties.
First of all, to avoid problems deep inside wxToolBar, always check the return code of LoadFile() or, alternatively, use wxBitmap::IsOk() to check that the bitmap was successfully loaded.
Second, while adding the handler explicitly as you did is perfectly fine, I'd recommend to just call wxInitAllImageHandlers() as it's simpler and has no real drawbacks unless you are looking to create the smallest program possible.
Finally, to address your real problem, the file clearly doesn't exist at the path you're loading it from. You can, of course, solve this by being careful not to change your working directly (or restore it after changing it) in your program and by placing the file in the correct place. But this is, as you discovered, error-prone, so a better idea is to always use full paths to your resources. To construct them, you will find wxStandardPaths useful, in particular its GetResourcesDir() method.