Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++ makefile

Status
Not open for further replies.

krotkruton

Programmer
Jan 3, 2005
6
0
0
US
I've had some experience (CS classes) with UNIX based C++, but now that I'm away from school, I started working with MS VC++ because I couldn't get anything else working. Anyway, I can't figure out how to set up a makefile in VC++.

Here's a makefile I modified from a sample I found on the web.

#############################################################################
# Makefile for building barmonkey
# Modified by Kruton 01/02/05
# Project: barmonkey
# Template: app
#############################################################################

####### Compiler, tools and options

CC = cl
CFLAGS = -nologo -W3 -O2 -GX
INCPATH = -I"$(QTDIR)\include"
LINK = link
LFLAGS = /NOLOGO /SUBSYSTEM:windows
LIBS = $(QTDIR)\lib\qt.lib user32.lib gdi32.lib comdlg32.lib wsock32.lib
MOC = moc

####### Files

HEADERS = inventory.h \
drinks.h \
users.h
SOURCES = inventory.cpp \
drinks.cpp \
users.cpp \
barmonkey.cpp
OBJECTS = inventory.obj \
drinks.obj \
users.obj \
barmonkey.obj
SRCMOC = moc_barmonkey.cpp
OBJMOC = moc_barmonkey.obj
TARGET = barmonkey.exe

####### Implicit rules

.SUFFIXES: .cpp .cxx .cc .c

.cpp.obj:
$(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $<

.cxx.obj:
$(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $<

.cc.obj:
$(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $<

.c.obj:
$(CC) -c $(CFLAGS) $(INCPATH) -Fo$@ $<

####### Build rules

all: $(TARGET)

$(TARGET): $(OBJECTS) $(OBJMOC)
$(LINK) $(LFLAGS) /OUT:$(TARGET) @<<
$(OBJECTS) $(OBJMOC) $(LIBS)
<<

moc: $(SRCMOC)

tmake: Makefile

Makefile: barmonkey.pro
tmake barmonkey.pro -o Makefile

clean:
-del users.obj
-del inventory.obj
-del drinks.obj
-del barmonkey.obj
-del moc_barmonkey.cpp
-del moc_barmonkey.obj
-del $(TARGET)

####### Compile

barmonkey.obj: barmonkey.cpp \
inventory.h \
drinks.h \
users.h

inventory.obj: inventory.cpp \
inventory.h

drinks.obj: drinks.cpp \
drinks.h \
inventory.h

users.obj: users.cpp \
users.h \
inventory.h


As some probably notice, there is nothing at the bottom regarding moc_barmonkey because I was trying to "fix" it and ended up just deleting it, and now I don't know what to do with it. Here is the error I get:

--------------------Configuration: test - Win32 Debug--------------------
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
NMAKE : fatal error U1073: don't know how to make 'moc_barmonkey.obj'
Stop.
Error executing nmake.

test.exe - 1 error(s), 0 warning(s)


I have a feeling that my makefile might be far more complicated then it needs to be, but I know that a simple fix should be adding something about moc_barmonkey.obj towards the end. Any help is greatly appreciated.

-Kruton
 
Create a visual studio project and add your source files to it, then you don't have to worry about makefiles.


/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
In the build rules you require $(OBJMOC) to be prepared to build $(TARGET). $(OBJMOC) is moc_barmonley.obj, but there is not explicit rule for creating mac_barmonkey.obj. There are several implict rules, but unless moc_barmonkey.cpp exists, then it can't supply the right rule.

An explicit rule would be:

$(OBJMOC): $(SRCMOC)

but then, of course, it will want to build SRCMOC.

A lot of your makefile should be supplied by the environment. The implicit rules, the "compilers, tools and options", should be preset.

As Perfnurt states, you should use the MSVC environment if you're working in MSC++ (and that's what this forum is about). It uses make under the hood, but it creates the makefile on the fly from your project settings. It hides a lot of the syntax problems, but, of course, also requires a depth of understanding of its own.
 
Since I always had to make my own makefiles before, I had no idea that VC++ would do it for me. After messing around with different projects and probably creating every wrong project before finally trying a console project, I got it working.

Anyway, now I have a bit better understanding of how VC++ works.
 
A console project is a "traditional" DOS-type app. It will run in a DOS box (CMD box for w2k/XP. A true windows app using the Windows SDK is a "Win32" app. The differences have to do with differing assumptions about compiler/linker options and included libraries. They all use makefile (or nmake, as MS calls it).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top