How can I compile and run project from command lin

2019-07-31 22:05发布

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 $<
%.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))

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?

3条回答
做自己的国王
2楼-- · 2019-07-31 22:40

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) or make -f <makefile name>.

NOTE: The windows path for c:\mydir1\mydir2 is in mingw /c/mydir1/mydir2. So you should reach your directory by typing cd /c/mydir1/mydir2.

If your project is configured to use Visual Studio (cl.exe compiler) you can:

  1. Start Visual studio console
  2. Start a cmd.exe prompt and after that run "c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat" (or your corresponding vcvars32.bat)

After you done this you go to your directory with cd c:\mydir1\mydir2 and type nmake (the make equivalent from visual studio package) or nmake /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).

查看更多
何必那么认真
3楼-- · 2019-07-31 22:53

The easiest solution is to download minigw for windows with gcc. Take a look at: http://www.mingw.org/

查看更多
Explosion°爆炸
4楼-- · 2019-07-31 22:57

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.

查看更多
登录 后发表回答