如何从命令行(Windows 7)编译并运行项目?
我有一个包含 makefile 的项目:
# a simple makefile
# Uncomment, if compression support is desired
#DCOMP=-DWITH_COMPRESSION
#ZLIB=-lz
#Compiler
CC=g++
# compiler switches
#CPPFLAGS=-g -I.
CPPFLAGS=-O -I.
CFLAGS=-O -I. $(DCOMP)
#LDFLAGS=-L/usr/local/lib
#libraries
LIBS= -lm $(ZLIB)
# Compilation rules
# target:source
%.o:%.c
$(CC) $(CFLAGS) -o $@ -c $<
%.o:%.cpp
$(CC) $(CPPFLAGS) -o $@ -c $<
# $@-target, $<-source
DNAME=f3dProjBasicNoComp12
PROGRAM=project
PROJ_OBJECTS= project.o f3d.o f3dGridLite.o
#the first (default)
all:$(PROGRAM)
project:$(PROJ_OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(PROJ_OBJECTS) $(LIBS)
clean:
rm -f $(PROGRAM) *.o core* *.ppm
pack:
make clean
(cd .. && tar cvzf $(DNAME).tgz $(DNAME))
我想在 Windows 上运行它。教授说我应该编译并运行它,但他没有告诉我如何在 Windows 上执行此操作。我读过我应该使用 nmake MakeFile,但是:
'nmake' is not recognized as an internal or external command,
operable program or batch file.
要运行应用程序,我应该使用 somethink,例如 project -x somethink.obj
。 但因为我无法编译 makefile,所以无法运行该项目。
你能帮助我吗?
I have a project which has a makefile:
# a simple makefile
# Uncomment, if compression support is desired
#DCOMP=-DWITH_COMPRESSION
#ZLIB=-lz
#Compiler
CC=g++
# compiler switches
#CPPFLAGS=-g -I.
CPPFLAGS=-O -I.
CFLAGS=-O -I. $(DCOMP)
#LDFLAGS=-L/usr/local/lib
#libraries
LIBS= -lm $(ZLIB)
# Compilation rules
# target:source
%.o:%.c
$(CC) $(CFLAGS) -o $@ -c lt;
%.o:%.cpp
$(CC) $(CPPFLAGS) -o $@ -c lt;
# $@-target, lt;-source
DNAME=f3dProjBasicNoComp12
PROGRAM=project
PROJ_OBJECTS= project.o f3d.o f3dGridLite.o
#the first (default)
all:$(PROGRAM)
project:$(PROJ_OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(PROJ_OBJECTS) $(LIBS)
clean:
rm -f $(PROGRAM) *.o core* *.ppm
pack:
make clean
(cd .. && tar cvzf $(DNAME).tgz $(DNAME))
And I want to run it on Windows. The professor has said that I should compile it and run, but he did not tell me how can I do this on Windows. I have read that I should use nmake MakeFile, but than:
'nmake' is not recognized as an internal or external command,
operable program or batch file.
To run the application, I should use somethink like project -x somethink.obj
.
But because I cannot compile the makefile I cannot run the project.
Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1) 您必须安装 Visual Studio
2) 您必须运行 Visual Studio 命令提示符(安装后您将在 Microsoft Visual Studio 开始菜单条目中找到它)并从那里调用
nmake
。1) You have to have Visual Studio installed
2) You have to run Visual Studio command prompt (you will find it in the Microsoft Visual Studio Start menu entry once you have it installed) and invoke
nmake
from there.最简单的解决方案是使用 gcc 下载适用于 Windows 的 minigw。看看:
http://www.mingw.org/
The easiest solution is to download minigw for windows with gcc. Take a look at:
http://www.mingw.org/
如果您的项目配置为使用 gcc/g++(如您的示例中所示),那么您应该安装 mingw。启动 mingw shell 后,进入目录并输入
make
(前提是您在安装 mingw 时安装了 make)或make -f
。注意:
c:\mydir1\mydir2
的 Windows 路径位于 mingw/c/mydir1/mydir2
中。因此,您应该通过输入 cd /c/mydir1/mydir2 来访问您的目录。如果您的项目配置为使用 Visual Studio(cl.exe 编译器),您可以:
"c:\Program Files\Microsoft Visual Studio 9.0\VC\bin \vcvars32.bat"
(或相应的vcvars32.bat
)完成此操作后,您可以使用
cd c:\mydir1\mydir2
转到您的目录并键入nmake
(Visual Studio 包中的 make 等效项)或nmake /f
。如果您需要其他工具链来编译,那么您应该遵循特定步骤。我记得要使用 Borland 编译器,您只需要设置
bcc32
可执行文件的路径。稍后编辑:
如果项目使用unix特定程序,您应该使用cygwin(如评论中提到)。
If your project is configured to use gcc/g++ (as in your example) then you should install mingw. After that you start the mingw shell, you go to your directory and type
make
(provided that you installed make when installing mingw) ormake -f <makefile name>
.NOTE: The windows path for
c:\mydir1\mydir2
is in mingw/c/mydir1/mydir2
. So you should reach your directory by typingcd /c/mydir1/mydir2
.If your project is configured to use Visual Studio (cl.exe compiler) you can:
"c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
(or your correspondingvcvars32.bat
)After you done this you go to your directory with
cd c:\mydir1\mydir2
and typenmake
(the make equivalent from visual studio package) ornmake /f <your makefile name>
.If you're required other toolchain to compile then you should follow specific steps. I remember that for using Borland compiler you only need to set the path to the
bcc32
executable.LATER EDIT:
In case the project uses unix specific procedure you should use cygwin (as mentioned in comments).