How to Use Makefiles in Visual Studio

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:

  1. 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 in tasks.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.

  2. make contains an interface engine, supporting suffix rules and support for wildcards. I don't think tasks.json support that. You can probably use some extra shell scripts to achieve the same, but it won't be as neat as how make does it.

  3. 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



Leave a reply



Submit