将Visual Studio Makefile转换为Linux Makefile [英] Converting a visual studio makefile to a linux makefile

查看:74
本文介绍了将Visual Studio Makefile转换为Linux Makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是makefile的新手,最近刚刚创建了一个可用于c ++项目的makefile.它有两个cpp文件和一个h文件.我正在尝试将我的文件转换为可在linux中工作,但似乎无法弄清楚该怎么做.有什么想法吗?

i am new to makefiles and have just rescently created a makefile that works for a c++ project. it has two cpp files and one h file. i am trying to convert my file to work in linux but cant seem to figure out how. any ideas?

EXE = NumberGuessingGame.exe
CC = cl
LD = cl
OBJ = game.obj userInterface.obj
STD_HEADERS = header.h
CFLAGS = /c
LDFLAGS = /Fe

$(EXE): $(OBJ)
    $(LD) $(OBJ) $(LDFLAGS)$(EXE)

game.obj: game.cpp $(STD_HEADERS)
    $(CC) game.cpp $(CFLAGS)

userInterface.obj: userInterface.cpp $(STD_HEADERS)
    $(CC) userInterface.cpp $(CFLAGS)

#prepare for complete rebuild
clean:
    del /q *.obj
    del /q *.exe

推荐答案

有关在Linux上对make的深入处理,请参见

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

有一些区别.二进制文件没有扩展名

There are a few differences. Binaries have no extension

EXE = NumberGuessingGame

编译器为gcc,但无需命名,因为内置了CC,对于LD也是一样.但是,由于您的文件名为.cpp,因此相应的编译器为g++,在make中为CXX.

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.

目标文件具有扩展名.o

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

编译器标志

CXXFLAGS = -c

/Fe的等效项只是-o,未指定为LDFLAGS,而是在链接器命令行中阐明.

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被称为 rm

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

重要的一点是,缩进是一个 tab 字符, no 空格.如果您有空格,make将抱怨

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.

这篇关于将Visual Studio Makefile转换为Linux Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆