How to use makefiles in Visual Studio?
A UNIX guy probably told you that. :)
You can use makefiles in VS, but when you do it bypasses all the built-in functionality in MSVC's IDE. Makefiles are basically the reinterpret_cast of the builder. IMO the simplest thing is just to use Solutions.
Good techniques to use Makefiles in VisualStudio?
We use a NAnt script, which at the compile step calls MSBuild. Using NAnt allows us to perform both pre- and post-build tasks, such as setting version numbers to match source control revision numbers, collating code coverage information, assembling and zipping deployment sources. But still, at the heart of it, it's MSBuild that's actually doing the compiling.
You can integrate a NAnt build as a custom tool into the IDE, so that it can be used both on a build or continuous integration server and by the developers in the same way.
Use Visual Studio debugger in Makefile-based solution
The following may work, no promises.
This assumes you've built the executable with correct debugging flags: /ZI
at a minimum, /Zi
will make your life orders of magnitude easier for hot-patching while debugging. And the appropriate /DEBUG
option to the linker.
Open a command prompt in the folder where you want the executable to run, and then type
<Path to Visual Studio.exe> <Path to your executable>
For example for an app I'm debugging that's:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe" sspf.exe
That'll open visual studio, and if you hit F-10 it'll step into your program, and you should see source.
If that works, you should be good to go. It'll ask if you want to save a .sln
file on exit, it's up to you if you do. If you don't, you will need to explicitly name the executable every time you start a new debug session, if you do, you'll have an additional file or files cluttering up your workspace, but will have the advantage that double clicking the .sln
file will get you right back into a debug session.
For your case, this is a total non-issue, but it is worth noting that the .sln
file created by doing this is only useful to debug the program, it can't be used to build it.
Is use of `make` meaningful when using VS Code?
On the surface, you can use either Makefiles or tasks.json
to execute various shell scripts. With the property dependsOn
of tasks.json
, you can do a topological sort of tasks that Makefile also does.
There are still things that make
does better than tasks.json
:
make
can check timestamps of files to find which files are outdated and which tasks it doesn't need to execute. Maybe you can do that using various shell scripts intasks.json
, but using Makefiles would be far more convenient. For very big projects with a lot of source code, this is a very great feature since you can save a lot of time instead of re-building 100s of files you didn't need to.make
contains an interface engine, supporting suffix rules and support for wildcards. I don't thinktasks.json
support that. You can probably use some extra shell scripts to achieve the same, but it won't be as neat as howmake
does it.Finally, Makefiles can be run in any system that has
make
, and therefore it is independent of VS Code.
If you're working on a small/simple enough project, you can absolutely work on it without using make
. For large projects, make
is the sensible choice.
In my college project, we are using Makefiles. We work on VS Code so we set the tasks.json
scripts to just use make commands with the said Makefile. You can do that as well if you like.
Related Topics
Function Template with an Operator
Setting Thread Priority in Linux with Boost
Is Std::String Thead-Safe with Gcc 4.3
Is Undefined Behavior Worth It
C++11 Lambdas: Member Variable Capture Gotcha
Is It a Good Practice to Use Unions in C++
Is Shrink_To_Fit the Proper Way of Reducing the Capacity a 'Std::Vector' to Its Size
Propagate Constness to Data Pointed by Member Variables
C++: Nested Template Classes Error "Explicit Specialization in Non-Namespace Scope"
Why am I Not Provided with a Default Copy Constructor from a Volatile
What Strategies Have You Used to Improve Build Times on Large Projects
Are There Any Issues with Allocating Memory Within Constructor Initialization Lists
Why Does Visual Studio Not Perform Return Value Optimization (Rvo) in This Case