67

I heard a lot about makefiles and how they simplify the compilation process. I'm using VS2008. Can somebody please suggest some online references or books where I can find out more about how to deal with them?

rgettman
  • 176,041
  • 30
  • 275
  • 357
chester89
  • 8,328
  • 17
  • 68
  • 113
  • It seems the makefile-style VS project doesn't work with some VS features, such as the Code Map. – smwikipedia Apr 28 '21 at 01:34
  • It seems the makefile-style VS project doesn't work with some VS features, such as the Code Map, even if you add the `/FR` compile option to generate the browse info. – smwikipedia Apr 28 '21 at 01:51

8 Answers8

56

The Microsoft Program Maintenance Utility (NMAKE.EXE) is a tool that builds projects based on commands contained in a description file.

NMAKE Reference

Alessandro Jacopson
  • 18,047
  • 15
  • 98
  • 153
19

To answer the specific questions...

I'm using VS2008. Can somebody please suggest some online references or books where I can find out more about how to deal with them?

This link will give you a good introduction into Makefiles by mapping it with Visual Studio.

Introduction to Makefiles for Visual Studio developers

I heard a lot about makefiles and how they simplify the compilation process.

Makefiles are powerful and flexible but may not be the best solution to simplify the process. Consider CMake which abstracts the build process well which is explained in this link.

CMake for Visual Studio Developers

ap-osd
  • 2,624
  • 16
  • 16
19

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.

John Dibling
  • 99,718
  • 31
  • 186
  • 324
  • 18
    .vcproj files have a lot of bloat, and grow unwieldy quite fast unless you're using something else to generate them (scons, cmake). – Tom Dec 09 '08 at 15:52
  • 65
    Plus Microsoft uses makefiles internally. No one would even dream of loading windows source code into a solution file. – Filip Frącz Mar 17 '09 at 20:20
  • 74
    This doesn't actually answer the question. – weberc2 Jul 11 '14 at 20:34
  • 2
    @John Dibling : "it bypasses all the built-in functionality in MSVC's IDE". What are built-in functionality that got bypassed? is optimizations got bypass too? – someone_ smiley Jan 29 '15 at 08:37
  • 1
    @someone_smiley: Optimizatons aren't bypasses. You would specify those in your makefile. – John Dibling Jan 29 '15 at 15:12
  • 3
    It is always good to support on different platform and not completely tight with MS. Especially if we are developing apps on Linux & Microsoft. – Yeo Aug 20 '15 at 15:50
  • 15
    How in the world is this the accepted Answer? It doesn't do anything to answer the perfectly valid question that was asked. – Zinki Sep 29 '17 at 08:50
  • Pantheios provides Visual C++ makefiles. What do I do with them? – Kyle Delaney Apr 29 '18 at 01:05
  • FWIW, I wouldn't have accepted this answer either. It doesn't answer the question. But SO was different back then. I've seen this q/a probably 20 times since I wrote this answer 12 years ago. (It's 5/21/2020 right now, smack in the middle of COVID). I honestly don't know enough about solution files these days to even know if the answer is legit, because I havent even use VS in probably 10 years. These days I spend about 90 percent of my time in Linux. The other 10 percent is spent in windows working on the frontend app. But the interesting thing is... I use VSCode in both – John Dibling May 22 '20 at 01:44
8

I actually use a makefile to build any dependencies needed before invoking devenv to build a particular project as in the following:

debug: coratools_debug
    devenv coralib.vcproj /build debug

coratools_debug: nothing
    cd ../coratools
    nmake debug
    cd $(MAKEDIR)

You can also use the msbuild tool to do the same thing:

debug: coratools_debug
    msbuild coralib.vcxproj /p:Configuration=debug

coratools_debug: nothing
    cd ../coratools
    nmake debug
    cd $(MAKEDIR)

In my opinion, this is much easier than trying to figure out the overly complicated visual studio project management scheme.

Jon Trauntvein
  • 4,453
  • 6
  • 39
  • 69
5

The VS equivalent of a makefile is a "Solution" (over-simplified, I know).

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
5

To summarize with a complete solution...

There are 2 options:

  1. Use NMAKE from the Developer Command Prompt for Visual Studio

The shortcut exists in your Start Menu. Look inside the makefile to see if there are any 'setup' actions. Actions appear as the first word before a colon. Typically, all good makefiles have an "all" action so you can type: NMAKE all

  1. Create a Solution and Project Files for each binary.

Most well designed open source solutions provide a makefile with a setup action to generate Visual Studio Project Files for you so look for those first in your Makefile.

Otherwise you need to drag and drop each file or group of files and folders into each New Project you create within Visual Studio.

Hope this helps.

justdan23
  • 560
  • 7
  • 9
2

Makefiles and build files are about automating your build. If you use a script like MSBuild or NAnt, you can build your project or solution directly from command line. This in turn makes it possible to automate the build, have it run by a build server.

Besides building your solution it is typical that a build script includes task to run unit tests, report code coverage and complexity and more.

mmiika
  • 9,970
  • 5
  • 28
  • 34
1

If you are asking about actual command line makefiles then you can export a makefile, or you can call MSBuild on a solution file from the command line. What exactly do you want to do with the makefile?

You can do a search on SO for MSBuild for more details.

Tim
  • 20,184
  • 24
  • 117
  • 214