笨的很,肯定没有仔细看文档
cc -o test main.o是Unix系统下编译C的命令,使用的编译程序是cc,cc经常是到gcc的一个符号链接
每一条规则后面是一个命令:
test: main.o
cc -o test main.o
make程序只是一个根据规则来执行命令的工具,实例中的命令是cc的编译命令,你用vc来编译怎能还用cc?vc中编译C/C++的编译器是cl.exe,所以cc应该换成cl,而且你还需要在msdn中查cl的编译命令,cl的选项和cc可不一样。
另外vc提供了makefile导出功能,IDE可以自动生成.mak扩展名的makefile文件。
举个例子,我写了一个hello world的程序:
工程由三个文件组成:
程序代码:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__98767A9E_4AED_415A_8D58_510A12773B35__INCLUDED_)
#define AFX_STDAFX_H__98767A9E_4AED_415A_8D58_510A12773B35__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__98767A9E_4AED_415A_8D58_510A12773B35__INCLUDED_)
程序代码:
// tt.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
程序代码:
// stdafx.cpp : source file that includes just the standard includes
// tt.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
在project中选Export Makefile,自动生成tt.mak
程序代码:
# Microsoft Developer Studio Generated NMAKE File, Based on tt.dsp
!IF "$(CFG)" == ""
CFG=tt - Win32 Debug
!MESSAGE No configuration specified. Defaulting to tt - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "tt - Win32 Release" && "$(CFG)" != "tt - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "tt.mak" CFG="tt - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "tt - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "tt - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "tt - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\tt.exe"
CLEAN :
-@erase "$(INTDIR)\StdAfx.obj"
-@erase "$(INTDIR)\tt.obj"
-@erase "$(INTDIR)\tt.pch"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\tt.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\tt.pch" /Yu"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\tt.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\tt.pdb" /machine:I386 /out:"$(OUTDIR)\tt.exe"
LINK32_OBJS= \
"$(INTDIR)\StdAfx.obj" \
"$(INTDIR)\tt.obj"
"$(OUTDIR)\tt.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "tt - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\tt.exe"
CLEAN :
-@erase "$(INTDIR)\StdAfx.obj"
-@erase "$(INTDIR)\tt.obj"
-@erase "$(INTDIR)\tt.pch"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\tt.exe"
-@erase "$(OUTDIR)\tt.ilk"
-@erase "$(OUTDIR)\tt.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\tt.pch" /Yu"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\tt.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\tt.pdb" /debug /machine:I386 /out:"$(OUTDIR)\tt.exe" /pdbtype:sept
LINK32_OBJS= \
"$(INTDIR)\StdAfx.obj" \
"$(INTDIR)\tt.obj"
"$(OUTDIR)\tt.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("tt.dep")
!INCLUDE "tt.dep"
!ELSE
!MESSAGE Warning: cannot find "tt.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "tt - Win32 Release" || "$(CFG)" == "tt - Win32 Debug"
SOURCE=.\StdAfx.cpp
!IF "$(CFG)" == "tt - Win32 Release"
CPP_SWITCHES=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\tt.pch" /Yc"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
"$(INTDIR)\StdAfx.obj" "$(INTDIR)\tt.pch" : $(SOURCE) "$(INTDIR)"
$(CPP) @<<
$(CPP_SWITCHES) $(SOURCE)
<<
!ELSEIF "$(CFG)" == "tt - Win32 Debug"
CPP_SWITCHES=/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\tt.pch" /Yc"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
"$(INTDIR)\StdAfx.obj" "$(INTDIR)\tt.pch" : $(SOURCE) "$(INTDIR)"
$(CPP) @<<
$(CPP_SWITCHES) $(SOURCE)
<<
!ENDIF
SOURCE=.\tt.cpp
"$(INTDIR)\tt.obj" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\tt.pch"
!ENDIF