How to follow symlinks in visual studio and cmake in windows? - windows

When building a c++ project in Visual Studio (2008 in this case), the compiler checks for each source file if there is already an .obj file and only rebuilds the .obj file if any of the input files, which are headers and a source file, are newer than the .obj.
This fails if any of the input files are symlinks because Visual Studio doesnt follow symlinks and only looks at the change date of the symlink itself.
E.g. Test.cpp (symlink 15:30) points to ../Common/Source/Test.cpp (changed 16:38) should produce
Test.obj (changed 15:31). Unfortunately VS wont follow symlinks and doesnt see that the original file was updated.
GNU make and gcc can follow symlinks, is there an equivalent in Visual Studio or is there another option for Windows? The change date of a symlink should also reflect the change date of the original file, IMHO, since a symlink cant be changed in Windows anyway.

Related

Visual Studio project built with cmake displays "File Modification Detected"

The Visual Studio 2019 project, which was built via cmake displays
File Modification Detected
The project ABC has been modified outside the environment
Reload ... Ignore ...
message.
How can I prevent cmake from updating the VS config files, for the project or system wide?
In what section of the cmake build files this behavior is defined (so that I can rebuild the project without this feature)?
No, you cannot prevent this (afaik). Consider the scenario where you add a source file to a target in a CMakeLists.txt file. CMake needs to update the Visual Studio project files it generated which results in project file(s) being overwritten. CMake sets up the solution in a way to ensure such an update on a modification of the cmake files. Visual Studio reacts to the solution/project files being overwritten by displaying the dialog you mentioned.
In general you'll want to click "Reload" which should just update the projects according to the modification in the cmake sources. If for a command line build tool shows up though, you may want to select "Ignore" though, since sometimes the build output is deleted on a reload of projects/the solution and you'll probably want to check the error message.
If you're interested: Overriding the project files happens in the ZERO_CHECK target.
If the dialog is displayed on a build even if you did not modify the cmake files since the last build, you may want to check the console for a warning in the output of cmake though; this may indicate that there may be some issue in your cmake files...

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.

Visual Studio 2013 not using include path

I have a simple empty Visual Studio 2013 C/C++ project to which added two files:
MyCode.cpp
MyCode.h
Inside MyCode.cpp, I have as the first line,
#include "mex.h"
mex.h is a MATLAB file located in C:\Program Files\MATLAB\MATLAB Compiler Runtime\v717\extern\include
I have gone to Project Properties -> C/C++ -> General and added "C:\Program Files\MATLAB\MATLAB Compiler Runtime\v717\extern\include" to my "Additional Include Directories".
And yet, VS never finds the file!
File 'mex.h' not found in current source file's directory or in build system paths.
It seems that the build system paths are not being updated with my additional include path.
I've tried using relative paths as well, deleting the .sdf file, and closing/reopening Visual Studio. It simply won't add the path.
For reference, this works fine in Visual Studio 2010.
Help!

CMake: add files as content to Visual Studio Solution

CMake since version 3.1 can create Windows Store/Windows Phone 8.1 projects.
Is it possible to add resource file (say, png image) to resulting Visual Studio 2013 project (Modern UI app) and mark it as content to force copying it to output directory when building from VS? If yes, how this can be achieved?
For example configure_file just adds file to the project directory
Looks like there's a flag for that called VS_DEPLOYMENT_CONTENT in cmake
http://www.cmake.org/cmake/help/v3.1/prop_sf/VS_DEPLOYMENT_CONTENT.html
By the way, Microsoft has a cmake fork with more update support for windows universal app that isn't a part of the cmake main repository yet.
https://github.com/Microsoft/CMake/
You might find it useful.
To copy files, say PNG images as you wanted, to the output directory, you can do like this:
file(GLOB files_needed_to_copy
your-data-directory/*.png
)
file(COPY ${files_needed_to_copy} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
This will make the copy operation happen while cmake-ing.

Visual Studio 2010 can't see /bin library of OpenCV

I'm trying to use OpenCv 2.2 in Visual Studio 2010.
I've configured everything by instruction:
http://opencv.willowgarage.com/wiki/VisualC%2B%2B
and by instruction from the book:
So I've added all /lib and /include paths.
When I build project, it compiles and before starting app, VS displays an error message that opencv_core220d.dll is missing.
This file is in C:/OpenCV2.2/bin as all .dll files. If I add this file to my working directory - it will be fine. Then VS displays error about every .dll file that I added in Linker-Input configuration ( but with .lib extension ).
So, if I add all .dlls file that I've added as .lib in Linker configuration - to my working directory, project will start.
But why? Why VC doesn't see OpenCV2.2/bin folder? Where is this pointed?
Because it doesn't know to look there by default. However, it does know to check the current directory for the DLLs.
You can tell it where to look by adding C:/OpenCV2.2/bin to your Path variable, or if you would rather not muck up your global Path you can set the Environment variable local to the C++ project.
I think that is the syntax for appending to the Path in VS2010, but I'm not sure, so Google it if that doesn't work :)

Resources