今天在本地看到一個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:\GitHub\lsd_1.6
進入目錄后執行編譯命令:
nmake -f Makefile
接着就撞見錯誤了:
1 D:\GitHub\lsd_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 # -----------------------------------------------------------------------------
接着使用編譯命令:
nmake -f Makefile1
就這樣編譯通過了:

1 D:\GitHub\lsd_1.6>nmake -f Makefile1 2 3 Microsoft (R) Program Maintenance Utility Version 14.00.24210.0 4 Copyright (C) Microsoft Corporation. All rights reserved. 5 6 cl -O3 -o lsd lsd_cmd.c lsd.c -lm 7 Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86 8 Copyright (C) Microsoft Corporation. All rights reserved. 9 10 cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release 11 cl : Command line warning D9002 : ignoring unknown option '-O3' 12 cl : Command line warning D9002 : ignoring unknown option '-lm' 13 lsd_cmd.c 14 lsd.c 15 Generating Code... 16 Microsoft (R) Incremental Linker Version 14.00.24215.1 17 Copyright (C) Microsoft Corporation. All rights reserved. 18 19 /out:lsd_cmd.exe 20 /out:lsd.exe 21 lsd_cmd.obj 22 lsd.obj 23 cl -o lsd_call_example lsd_call_example.c lsd.c -lm 24 Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86 25 Copyright (C) Microsoft Corporation. All rights reserved. 26 27 cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release 28 cl : Command line warning D9002 : ignoring unknown option '-lm' 29 lsd_call_example.c 30 lsd.c 31 Generating Code... 32 Microsoft (R) Incremental Linker Version 14.00.24215.1 33 Copyright (C) Microsoft Corporation. All rights reserved. 34 35 /out:lsd_call_example.exe 36 /out:lsd_call_example.exe 37 lsd_call_example.obj 38 lsd.obj
注意:其實makefile中應該還有其他需要修改的,但是簡單編譯一個exe已經實現了,至於其他需要修改的有時間再研究。