- Visual Studio Code Makefile Windows
- Vs Code Makefile
- Visual Studio Code Makefile Example
- Visual Studio Code Makefile Debug
VS Code Makefile Tools. This extension provides IntelliSense configurations to the VS Code C/C Extension for Makefile projects. It also provides convenient commands to build, debug,. Building in Visual Studio is via a menu item in the IDE or invoking devenv.exe on the.sln file at the command prompt. This will automatically create the necessary directories and build only the files modified after the last build. Initiating a build with makefiles is to. Before that PR lands, you may be able to fix this locally by editing the application itself. On OSX where applications are really just folders, you can find the language configuration for Makefiles in Visual Studio Code.app/Contents/Resources/app/extensions/make. Open up make.configuration.json and add 'insertSpaces': false on line 2. That fixed it for me.
Makefiles support for VSCode. đź’Ą WARNING From version 1.21, Visual Studio Code now has a builtin extension to support Makefiles (see this folder). Don't use my extension! Install this extension to have syntax support for GNU Makefiles for Visual Studio Code. With the VSCode extension market.Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. VS Code C/C Makefile Project. This extension is generating a simple C/C project structure together with a Makefile which fits almost 99% of all small project's needs. Tip: Just initialize the project in the current working directory with Ctrl+Shift+P on a Windows/Linux or CMD+Shift+P on a Mac and choose C/C Make: INIT Project.
Preface
Introduction
Under the hood of Visual Studio
GNU/Linux Equivalent
Visual Studio to Make Utility mapping
Example
Source Structure
Build
RunMakefile
Details
Targets
Dependencies
Contents
NMake
Conclusion
External Links
If you develop software only on Windows using Visual studio, it’s a luxury. Enjoy it while it lasts. Sooner than later, you will come across Makefiles, maybe exploring some software on Linux or the misfortune of having a build system that uses make
with Cygwin on Windows.
Now you figure out that Makefiles are text files and open it in an editor hoping to get some insight into its workings. But, what do you see? Lots of cryptic hard to understand syntax and expressions. So, where do you start? Internet searches for make
and Makefiles
provide a lot of information but under the assumption that you come from a non-IDE Unix/Linux development environment. Pampered Visual Studio developers are never the target audience.
Here I will try to relate to the Visual Studio build system which will hopefully give an easier understanding of Makefiles. The goal is not to provide yet another tutorial on makefiles (because there are plenty available on the internet) but to instill the concept by comparison.
Visual Studio provides features that are taken for granted until you have to read/create a classic Makefile
. For example, Visual Studio auto-magically does the following.
- Compiles all the sources in the project file
- Create an output directory and puts all the intermediate object files in it
- Manages dependencies between the source and object files
- Manages dependencies between the object files and binaries
- Links the object files and external dependent libraries to create binaries
All of the above have to be explicitly specified in a Makefile
. The make
utility in some ways is the equivalent of Visual Studio devenv.exe
(without the fancy GUI).
Visual Studio is essentially a GUI over the compilation and link process. It utilizes an underlying command line compiler cl.exe
and linker link.exe
. Additionally, it provides a source code editor, debugger and other development tools.
A simple win32 console application project in Visual Studio is shown below. You have a solution
file which contains a project
file.
Invoking a build on the solution in Visual Studio calls something like the following under the hood. Yes, it looks ugly! But that is the the project properties translated to compiler/linker flags and options.
It is very similar in GNU/Linux. The equivalent of a compiler and linker is gcc
, the GNU project C and C++ compiler. It does the preprocessing, compilation, assembly and linking.
Shown below is a very simple Makefile
which can be accessed from GitHub https://github.com/cognitivewaves/Simple-Makefile.
Visual Studio Code Makefile Windows
Invoking the make
command to build will output the following.
Below is a table relating Visual Studio aspects to Make utility. At a high level, the Project
file is equivalent to a Makefile
.
Visual Studio | make Utility | |
---|---|---|
Command | devenv.exe | make |
Source structure | Solution (.sln ) has project files (typically in sub-directories) | Starting at the root, each Makefile can indicate where other Makefile s (typically in sub-directories) exist |
Library build dependency | Solution (.sln ) has projects and build order | Makefile |
Source files list | Project (.vcproj ) | Makefile |
Source to Object dependency | Project (.vcproj ) | Makefile |
Compile and Link options | Project (.vcproj ) | Makefile |
Compiler | cl.exe | gcc, g++, c++ (or any other compiler, even cl.exe ) |
Linker | link.exe | gcc, ld (or any other linker, even link.exe ) |
Download the example sources from GitHub at https://github.com/cognitivewaves/Makefile-Example.
Note that very basic Makefile
constructs are used because the focus is on the concept and not the capabilities of make itself.
Source Structure
Build
Visual Studio | make Utility |
---|---|
Building in Visual Studio is via a menu item in the IDE or invoking devenv.exe on the .sln file at the command prompt. This will automatically create the necessary directories and build only the files modified after the last build. | Initiating a build with makefiles is to invoke the make command at the shell prompt. Creating output directories has to be explicitly done either in the Makefile or externally. |
In this example, to keep the makefiles simple, the directories are created at the shell prompt.
The make
utility syntax is shown below. See make
manual pages for details.
Execute the command make
and specify the “root” Makefile
. However, it is more common to change to directory where the “root” Makefile
exists and call make
. This will read the file named Makefile
in the current directory and call the target all
by default.
Notice how make
enters sub-directories to build. This is because of nested Makefiles
which is explained later in the Makefiles Details section.
Run
Once the code is built, run the executable. This is nothing specific to makefiles but has been elaborated in case you are not familiar with Linux as you will notice that by default is will fail to run with an error message.
This is because the executable app.exe
requires the shared object libmath.so
which is in a different directory and is not in the system path. Set LD_LIBRARY_PATH
to specify the path to it.
Makefile Details
The basis of a Makefile
has a very simple structure.
The [tab]
separator is very important! Spaces instead of a [tab]
is not the same. You will see rather obscure error messages as shown below.Makefile:12: *** missing separator. Stop.
Targets
Here target
is a physical file on disk. When the target
is more of a label, then it has to be tagged as .PHONY
to indicate that the target is not an actual file.
Visual Studio | make Utility |
---|---|
Visual Studio by default provides options to clean and rebuild a project or solution. | Clean and rebuild have to be explicitly written in a makefile as targets which can then be invoked. |
A typical case would be to clean
before rebuilding.
Dependencies
Dependencies
can be files on disk or other targets (including phony targets).
Visual Studio | make Utility |
---|---|
Visual Studio by default supports implicit dependencies (source to object files) within a project. Library(project) dependencies have to specified in the solution file | Every dependency has to be explicitly defined in makefiles |
For example, the target all
, depends on app.exe
which in turn depends on libmath.so
. If you remove app.exe
, make is capable of recognizing that libmath.so
need not be built again.
Contents
File: Makefile
File: math/Makefile
File: app/Makefile
NMake is the native Windows alternative to the *nix make utility. The syntax is very similar to *nix makefiles. However, this does not mean that *nix makefiles can be executed seamlessly on Windows. See Makefiles in Windows for a discussion.
Makefiles are very powerful and gives a lot of control and flexibility compared to Visual Studio, but the content is not easily understandable. As an alternative, CMake has adopted similar concepts but the script is much easier and more readable. See CMake and Visual Studio.
:boom: WARNING From version 1.21, Visual Studio Code now has a builtin extension to support Makefiles (see this folder).Don’t use my extension!
Install this extension to have syntax support for GNU Makefiles for Visual Studio Code.
Installation
With the VSCode extension market. Launch VS Code Quick Open (Ctrl+P
), paste the following command, and press enter:
(or look for “Makefile” in the extension list, mine is the first one.)
More details can be found on the marketplace website, or on GitHub.
And the installation can also be done manually:
Features and demo
- Syntax support for Makefile.
- Comment or uncomment one or more line with the default comment shortcut.
Requirements
No requirements.(Probably a VSCode version more recent that 1.0 ? I have v1.17).
Extension Settings
No settings.
Known Issues
Vs Code Makefile
See the bug tracker for a list of open issues.Please fill a new issue if you find a bug!
Release Notes
0.0.3
- Added badge, and check that the extension can be uninstalled and reinstalled with success on another laptop.
0.0.2
- Better README.md file.
0.0.1
- First version, directly imported from TextMate language file from a SublimeText3 extension (Makefile-plus). I used
yo code
.
Visual Studio Code Makefile Example
TODO task
- Embed checkmake as a linting tool.
- Write a magical generic
.vscode/launch.json
file that adds any Makefile rule as a possible launch task (like this extension for ST3).
:scroll: License ?
Visual Studio Code Makefile Debug
MIT Licensed (file LICENSE).© Lilian Besson, 2017.