Converting a Visual Studio Makefile to a Linux Makefile

Converting a visual studio makefile to a linux makefile

For in depth treatment of make on Linux, see GNU make.

There are a few differences. Binaries have no extension

EXE = NumberGuessingGame

The compiler is gcc, but need not be named, because CC is built in, same goes for LD. But since your files are named .cpp, the appropriate compiler is g++, which is CXX in make.

Object files have extension .o

OBJ = game.o userInterface.o
STD_HEADERS = header.h

Compiler flags

CXXFLAGS = -c

The equivalent for /Fe is just -o, which is not specified as LDFLAGS, but spelled out on the linker command line.

Usually, you use the compiler for linking

$(EXE): $(OBJ)
$(CXX) $(LDFLAGS) $(OBJ) -o $(EXE)

You don't need to specify the rules for object creation, they are built in. Just specify the dependencies

game.o: $(STD_HEADERS)
userInterface.o: $(STD_HEADERS)

del is called rm

clean:
rm -f $(OBJ)
rm -f $(EXE)

One important point is, indentation is one tab character, no spaces. If you have spaces instead, make will complain about

*** missing separator.  Stop.

or some other strange error.

Convert a makefile to a VS project

The only real option you have here is to manually do the conversion (or use the Makefile Project Wizard). You say you have 'a few' makefiles, don't know how much that is, but unless you're talking about > 10 or so it's not that much work to manually create a Visual Studio project for these. After all, all you do is create a new dll project and add source files to it. The default compiler/linker flags hardly need any tweaking. Oh yeah if you do tweak them, make sure to do those changes in a property sheet instead of in the project itself: the property sheet can be reused by other projects, it's a simple matter of the DRY principle.

Why is this the only real option? Firstly there is no tool that can reliably convert any arbitrary makefile to a VS project, simpy because makefiles can be in any format you want and a lot of their functionality simply has no counterpart in a VS project. Secondly, VS6 is at this date about 15 years old so even if you get it to run on your machine, the output it produces is still ancient and definitely not what you want to use for your projects.

How do I create a makefile from a Visual Studio solution file?

This used to be possible in VC6, it had an option to generate a makefile from a .dsp project file. No more, the build process has changed too much to make this achievable.

Not a real problem, you can have the makefile invoke the vcbuild.exe tool, it builds a .vcproj project. Important switches you'll want to use in your makefile:

  • /clean: use that in your clean: target
  • /rebuild: use in your rebuild: target
  • /nocolor: makes build output look battleship gray like other build tools
  • /platform: selects the configuration you want to build (e.g: /platform:win32)

For example:

vcbuild /platform:win32 example.vcproj release

Note that the build system got a major revision in VS2010, you'll use msbuild.exe instead to build the .vcxproj project.

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.



Related Topics



Leave a reply



Submit