Windows使用nmake和Makefile编译c++
今天在本地看到一个lsd_1.6的源文件,不知道什么时候看LSD时下载的,里面只有一个Makefile和源文件。
想到在Linux下可以只用一个make命令就可以得到可执行程序,在Windows下是不是以可以一个命令就得到EXE程序呢,想到了nmake。
原来的Makefile是这样写的:
1 # ----------------------------------------------------------------------------- 2 # 3 # LSD - Line Segment Detector on digital images 4 # 5 # Copyright (c) 2007-2011 rafael grompone von gioi <grompone@gmail.com> 6 # 7 # This program is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU Affero General Public License as 9 # published by the Free Software Foundation, either version 3 of the 10 # License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU Affero General Public License for more details. 16 # 17 # You should have received a copy of the GNU Affero General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 # ----------------------------------------------------------------------------- 21 22 all: lsd lsd_call_example 23 24 lsd: lsd.c lsd.h lsd_cmd.c 25 cc -O3 -o lsd lsd_cmd.c lsd.c -lm 26 27 lsd_call_example: lsd.c lsd.h lsd_call_example.c 28 cc -o lsd_call_example lsd_call_example.c lsd.c -lm 29 30 doc: lsd.c lsd.h doxygen.config 31 doxygen doxygen.config 32 33 clean: 34 rm -f lsd lsd_call_example 35 36 cleandoc: 37 rm -rf doc 38 39 # -----------------------------------------------------------------------------
由于自己也不怎么会使用nmake就抱着试试看的态度试了一把。
去windows下打开这个:
然后 执行下面的命令,进入到lsd_1.6目录下:
cd /d D:GitHublsd_1.6
进入目录后执行编译命令:
nmake -f Makefile
接着就撞见错误了:
1 D:GitHublsd_1.6>nmake -f Makefile 2 3 Microsoft (R) Program Maintenance Utility Version 14.00.24210.0 4 Copyright (C) Microsoft Corporation. All rights reserved. 5 6 cc -O3 -o lsd lsd_cmd.c lsd.c -lm 7 'cc' 不是内部或外部命令,也不是可运行的程序 8 或批处理文件。 9 NMAKE : fatal error U1077: 'cc' : return code '0x1' 10 Stop.
原来是nmake不认识cc,果然不是一家人,联想到vs使用的编译命令是cl,果断把cc替换成cl,然后新建了一个Makefile1,只把原来Makefile里面的cc替换成cl.
Makefile1内容如下:
1 # ----------------------------------------------------------------------------- 2 # 3 # LSD - Line Segment Detector on digital images 4 # 5 # Copyright (c) 2007-2011 rafael grompone von gioi <grompone@gmail.com> 6 # 7 # This program is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU Affero General Public License as 9 # published by the Free Software Foundation, either version 3 of the 10 # License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU Affero General Public License for more details. 16 # 17 # You should have received a copy of the GNU Affero General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 # ----------------------------------------------------------------------------- 21 22 all: lsd lsd_call_example 23 24 lsd: lsd.c lsd.h lsd_cmd.c 25 cl -O3 -o lsd lsd_cmd.c lsd.c -lm 26 27 lsd_call_example: lsd.c lsd.h lsd_call_example.c 28 cl -o lsd_call_example lsd_call_example.c lsd.c -lm 29 30 doc: lsd.c lsd.h doxygen.config 31 doxygen doxygen.config 32 33 clean: 34 rm -f lsd lsd_call_example 35 36 cleandoc: 37 rm -rf doc 38 39 # -----------------------------------------------------------------------------