Add MinGW directory to $PATH only for Visual Code Studio - windows

I would like to use Visual Studio Code to compile and debug projects (C++, Nim), but I don't want to add the tool paths to my global Windows PATH settings, to avoid conflicts with other applications. In particular, I don't want to add the MinGW path.
How can I setup Visual Studio Code to add a path for all the tools - not only the terminal?
What I have tried
I saw a few similar questions, including this one which is somewhat outdated but has a few recent comments. I changed my VCS user settings by adding this:
"terminal.integrated.env.windows": {
"PATH": "${env:PATH}c:\\dev\\msys64\\mingw64\\bin"
},
and sure enough, if I open a terminal and type gcc, it executes normally, or if I check $env:PATH, I can see that it is set as expected.
But when I do Start debugging or Run without debugging from the editor, it fails:
Problems loading reference 'vscode://schemas/ignoredSettings': Unable to load schema from 'vscode://schemas/ignoredSettings': cannot open vscode://schemas/ignoredSettings. Detail: Unable to resolve text model content for resource vscode://schemas/ignoredSettings.
Note that it works fine if I add the MinGW bin path to my Windows PATH instead, but that's what I'm trying to avoid.

Related

Is there a way to change the extensions folder location for Visual Studio Code?

I've put Visual Studio Code on OneDrive, for the purpose of syncing it with its settings across my devices.
However, extensions are stored in %USERPROFILE%\.vscode\extensions on Windows.
Is it possible to change this folder's location so I can put it in the main Visual Studio Code folder?
At first I thought that copying the extensions in the resources\app\extensions of Visual Studio Code folder will be a nice workaround, but that doesn't work.
I've also searched for a solution on the documentation page and in the user settings, with no results.
What I did - after installing Visual Studio Code for the first time, I checked the documentation and added at the end of 'Target' field of editor's shortcut the following (there's a space before the two dashes):
--extensions-dir="DRIVELETTER:\VSCODE\extensions"
--user-data-dir="DRIVELETTER:\VSCODE\settings"
where DRIVERLETTER and VSCODE are the corresponding drive and directory where Visual Studio Code is installed. So mine looks like this:
"D:\Microsoft VS Code\Code.exe" --extensions-dir="D:\Microsoft VS Code\extensions"
Here is for the user data directory:
"D:\Microsoft VS Code\Code.exe" --user-data-dir="D:\Microsoft VS Code\settings"
Accessing the 'Target' field is done by right-clicking the shortcut and choosing 'Properties'
Anyway, there's a simpler solution to that problem - just use the portable version of Visual Studio Code. It works under Windows, Linux, and macOS:
Enable Portable Mode
Windows and Linux
After unzipping the Visual Studio Code download, simply create a data folder within Visual Studio Code's folder:
|- VSCode-win32-x64-1.25.0-insider
| |- Code.exe (or code executable)
| |- data
| |- ...
From then on, that folder will be used to contain all Visual Studio Code data, including session state, preferences, extensions, etc.
The data folder can be moved to other Visual Studio Code installations. This is useful for updating your portable Visual Studio Code version: simply move the data folder to a newer extracted version of Visual Studio Code.
macOS
On macOS, you need to place the data folder as a sibling of the application itself. Since the folder will be alongside the application, you need to name it specifically so that Code can find it. The default folder name is code-portable-data:
|- Visual Studio Code.app
|- code-portable-data
Portable mode won't work if your application is in quarantine, which happens by default if you just downloaded Visual Studio Code. Make sure you remove the quarantine attribute, if portable mode doesn't seem to work:
xattr -dr com.apple.quarantine Visual\ Studio\ Code.app
Note: On Insiders, the folder should be named code-insiders-portable-data.
UPDATE 14.12.2021
From Visual Studio Docs
Note: Do not attempt to configure portable mode on an installation from the Windows User or System installers. Portable mode is only supported on the Windows ZIP (.zip) archive. Note as well that the Windows ZIP archive does not support auto update.
A little hack:
Create a symbolic link to the folder %USERPROFILE%\.vscode\extensions under the Visual Studio Code install path.
https://code.visualstudio.com/docs/editor/extension-gallery
code --extensions-dir 'new_directory_to_set'
Set the root path for extensions.
Follow the below steps for changing the extension path in VS.
Set "code" path in environment variable.
path = VS_CODE_INSTALL_DIRECTORY/bin;
Open VS , in VS terminal execute the below command.
code --extensions-dir "new_directory_path"
Install the required extension.
All Done.
Note:Dont forget to vote the answer
According to this page, after installing VS Code we should make a language profilers folder like this:
mkdir code_profiles
cd code_profiles
mkdir code-ruby
cd code-ruby
mkdir exts
mkdir data
For Windows, I prepared a batch file (.bat) for each language I work on, it contains this line:
Start "" "D:\programs\VSCode\code.exe" --extensions-dir D:\programs\VSCode\code_profiles\code-python\exts --user-data-dir D:\programs\VSCode\code_profiles\code-python\data .
This is for Python. If I work on PHP, I will make code-php folder, then make exts and data folders in it and prepare another batch file for PHP, just like the one I made for python.
I put this batch file on the main project folder then double click on it to run VS Code with the preferred profile.

CMAKE does not create INSTALL project in Visual Studio

I am trying to compile a Library using CMAKE-gui 3.0.2 and Visual Studio express 2013.
Everything seems to be fine during the configuration/generation process in cmake-gui, as I am able to set the CMAKE_INSTALL_PREFIX variable to the path in which I want to have my library installed. And I got no errors during configuration and generation.
I then open the generated .sln file in which I can build the ALL_BUILD target, which runs smoothly with no errors and no targets skipped.
However, the INSTALL target is simply not present in the Solution Explorer, therefore I really do not have any idea on how to install the library.
Upon further inspection, I noticed that cmake did create a file called cmake_install.cmake, but I don't know what should I do with it.
CMake will only generate the INSTALL target when there is actually anything to install. It would seem you have no install() commands in your project.
Presence of the variable CMAKE_INSTALL_PREFIX does not imply anything - the variable is always present, and is used to control the installation destination when there is anything to install.
Likewise, the file cmake_install.cmake is always created; but if you inspect it, you'll find it's basically a no-op in your case (probably just some messages, setting CMake variables and possibly creating a manifest which is not used for anything).

Visual Studios 2010 the program can't start because opencv_core243.dll is missing

I am learning how to use OpenCV and as practice I ran a program (in Release mode, x64). I had 0 compiler errors but got a pop-up screen that said:
"the program can't start because opencv_core243.dll is missing"
However, I made sure I declared the correct environment variables and specified the necessary libraries/directories. My problem was fixed when I copied the following .dll files into x64/Release:
opencv_core243.dll
opencv_highgui243.dll
opencv_imgproc243.dll
My program compiles fine now and works. However, I would like to know why. It feels cheap to copy and paste these .dll files. Did I miss a step where these .dll files would be generated automatically?
The actual solution for this problem is to append the path of opencv bin directory to the System PATH environment variable.
Have a look at this answer describing the complete procedure to install OpenCV in Visual Studio 2010.
There is a disadvantage of this approach. The prebuilt OpenCV x86 and x64 binaries have same names. So by appending the path of OpenCV to the PATH variable, you can execute either the 32 bit version or the 64 bit version at a time. To run the other version, you have to change the PATH variable.
An alternative to this, (my personal favorite) also involves copying the dlls to output directory, but this is done automatically at the end of compilation. What I do, is to create new environment variables for x86 and x64 dll paths. I create the User Variables CV_BIN32 and CV_BIN64 containing the paths of x86 and x64 dlls respectively.
After creating the User Variables, open your OpenCV project, go to Project Properties -> Build Events -> Post-Build Event -> Command Line.
Add the copy commands for the dlls you require at the runtime.
This one is for Win32 Release Configuration:
copy "$(CV_BIN32)\opencv_core243.dll" "$(OutDir)"
copy "$(CV_BIN32)\opencv_highgui243.dll" "$(OutDir)"
You can change them for all the 4 configurations, (Debug/Release),(Win32/x64)
Now when the project build procedure completes, the specified dlls will be copied to the output directory automatically, and the error will not be shown.

Batch Builds in Visual Studio 6 for VC++ project

In VS 2008 and VS 2010, one can easily create a solution and modify the "Solution Configuration". We can choose what configuration each project gets built in when we trigger a build at the solution level.
Is such a facility available in the Visual Studio 6.0?
In my experience:
when a configuration is chosen (form the list available) in VS6 for a VC++ project, the dependencies (which themselves have multiple configurations defined) get built in some random order. There is no way to control the configurations of dependencies at build time.
"Batch Build" does come close to this but is not as flexible for my purpose.
I have tried various options in the VS6.
Hope I am clear.
Here is a link on the MSDEV command line.
https://msdn.microsoft.com/en-us/library/aa699274(v=vs.60).aspx
There is a way to control the building of dependencies. Specify /NORECURSE and dependencies will not be built.
I use /REBUILD with /NORECURSE to keep the dependencies from getting built.
And I build each project one at a time inside the workspace in a bat file by doing a chdir to the subdirectory and calling MSDEV just for that subproject:
msdev myproject.dsp /MAKE "myproject - Win32 Debug" /REBUILD /NORECURSE > Build.log
Then I cd to the next project directory one at a time.
On a side note, I had difficulties for several years where NMAKE would not work for my specific tasks. Turns out that the PATH environment variable inside MSDEV (Visual Studio 6.0) is different from the PATH environment variable of a command shell you would run NMAKE on.
The Path used by the MSDEV shell is the %PATH% at the time Visual Studio 6 was installed. We use this and poke the registry as needed for MSDEV to get the correct path setup when switching revisions of our software; however this doesn't help update the %PATH%. The MSDEV path can be queried with a query script. I don't have my example handy.
That is why builds in MSDEV sometimes work when builds using the command line don't, as the path to DLLs differ, and any custom build steps that run .exe will not work outside of the MSDEV environment unless the path is updated.
I have a script somewhere that reads the queries the registry to extract the MSDEV path and update PATH of a shell so that batch scripts doing nmake will work as they would inside the MSDEV shell environment. The problem with the REGISTRY QUERY is that the return arguments differ with different flavors of Windows (XP/SERVER2003/...).
One thing I just discovered is that Incredibuild works with the old VS6.0 MSDEV IDE. This is a game changer. It distributes builds. I'm evaluating it now, but it might be useful to anyone waiting for long VS6.0 builds.

Building Qt for Visual Studio 2010 - cannot open file 'qtmaind.lib'

I'm trying to start a C++ Qt application and have it run and compile in Visual Studio 2010.
Doing some googling, I found that there was a Visual Studio Qt Add-in, and so I installed this. I already had a MinGW Qt binary installed, and when this did not work, I found that you have to compile the source for Visual Studio 2010 (the VS 2008 binary will cause deployment issues).
Using this as a guide: How to build Qt for Visual Studio 2010, I compiled the open source version, and added it to the PATH, along with a QTDIR env variable. Hoping that I got it finally working, I created a "Qt Application" using the New Project Wizard in Visual Studio 2010. Once I finished, I tried to build the program, only to see the following error:
1>LINK : fatal error LNK1104: cannot open file 'qtmaind.lib'
I looked in the C:\QT\lib folder, and found that I only have a qtmaind.prl, but no clue as to why there is no qtmaind.lib.
I am able to echo the QMAKESPEC environmental variable to get a 'win32-msvc2010' output.
I've tried several different combinations of flags for the configure step, including the one in the link, and even tried manually setting the -platform flag.
If anyone can offer any help, it would be greatly appreciated! :D
Just ran across this same problem. I changed the "-release" flag from the linked guide to "-debug-and-release", and then it built the qtmaind.lib library (presumably, that "d" suffix stands for debug).
I encountered this issue when running a project whose settings were hardcoded for a particular machine setup.
I could see that the vcxproj file had something like:
C:\Qt\4.8.1\libqtmaind.lib
I could not find this lib file in my machine. I replaced the line by:
C:\Qt\4.7.3\lib\Qtmaind.lib
It looks like the names of library files are different across Qt versions.Or, maybe the library files were renamed.
Also, the 'd' denoted debug. If you cannot find any lib file post-fixed by 'd', it is likely that you did not 'make' a debug version of Qt.
You can cross check this by opening the .Sln file created by configure. Mine was named Projects.sln. You can open this in notepad and see if win32-debug configurations are present.
This might be a QMAKESPEC issue. Try setting your QMAKESPEC environment variable to
win32-msvc2010
and rebuild Qt like that. This should give you .lib files in your Qt folder
in QT 5.3 with vs 2013
in properties -> linker -> input
remove ANY path for qt libraries such qtmaind.lib
this is known BUG

Resources