MSYS+mingw 配置makefile

在阅读本文前请先确认你已经了解了

http://blog.csdn.net/dcmilan/article/details/7983697

http://blog.csdn.net/dcmilan/article/details/7986961

 

1.安装MSYS

MSYS在mingw的官网上可以下载,我这里使用1.0版本

安装完之后在C:\msys\1.0\bin文件夹里会有GNU的make

在cmd下使用make时,需要显示调用全路径C:\msys\1.0\bin\make

 

2.准备cpp和makefile

// hello.cpp
#include <iostream>

int main( )
{
   std::cout << "Hello, World!\n";
} 

 

// makefile(这一行在代码中不要出现,makefile中的命令行部分要以制表符tab开头,而不是空格)
# This is the default target, which will be built when
# you invoke make
.PHONY: all
all: hello

# This rule tells make how to build hello from hello.cpp
hello: hello.cpp
	g++ -o hello hello.cpp

# This rule tells make to copy hello to the binaries subdirectory,
# creating it if necessary
.PHONY: install
install:
	C:/msys/1.0/bin/mkdir -p binaries
	C:/msys/1.0/bin/cp hello binaries

# This rule tells make to delete hello and hello.o
.PHONY: clean
clean:
	C:/msys/1.0/bin/rm -f hello



 

建立一个文件夹hello,然后将以上代码在hello文件夹里创建对应文件hello.cpp和makefile

 

3.执行make命令

在cmd环境下切换目录到hello下

执行命令C:/msys/1.0/bin/make hello

 

生成hello.exe

 

然后再执行C:/msys/1.0/bin/make install

 

创建一个binaries文件夹,并将hello.exe复制到其中

 

注意:这里的makefile是完整的文件名,make命令

 

会自动找到这个文件,并执行文件中对应段的操作

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值