今天在本地看到一个lsd_1.6的源文件,不知道什么时候看LSD时下载的,里面只有一个Makefile和源文件。

想到在Linux下可以只用一个make命令就可以得到可执行程序,在Windows下是不是以可以一个命令就得到EXE程序呢,想到了nmake。

原来的Makefile是这样写的:

 # -----------------------------------------------------------------------------
#
# LSD - Line Segment Detector on digital images
#
# Copyright (c) - rafael grompone von gioi <grompone@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ----------------------------------------------------------------------------- all: lsd lsd_call_example lsd: lsd.c lsd.h lsd_cmd.c
cc -O3 -o lsd lsd_cmd.c lsd.c -lm lsd_call_example: lsd.c lsd.h lsd_call_example.c
cc -o lsd_call_example lsd_call_example.c lsd.c -lm doc: lsd.c lsd.h doxygen.config
doxygen doxygen.config clean:
rm -f lsd lsd_call_example cleandoc:
rm -rf doc # -----------------------------------------------------------------------------

由于自己也不怎么会使用nmake就抱着试试看的态度试了一把。

去windows下打开这个:

然后 执行下面的命令,进入到lsd_1.6目录下:

cd /d D:\GitHub\lsd_1.

进入目录后执行编译命令:

nmake -f Makefile

接着就撞见错误了:

 D:\GitHub\lsd_1.>nmake -f Makefile

 Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation. All rights reserved. cc -O3 -o lsd lsd_cmd.c lsd.c -lm
'cc' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
NMAKE : fatal error U1077: 'cc' : return code '0x1'
Stop.

原来是nmake不认识cc,果然不是一家人,联想到vs使用的编译命令是cl,果断把cc替换成cl,然后新建了一个Makefile1,只把原来Makefile里面的cc替换成cl.

Makefile1内容如下:

 # -----------------------------------------------------------------------------
#
# LSD - Line Segment Detector on digital images
#
# Copyright (c) - rafael grompone von gioi <grompone@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ----------------------------------------------------------------------------- all: lsd lsd_call_example lsd: lsd.c lsd.h lsd_cmd.c
cl -O3 -o lsd lsd_cmd.c lsd.c -lm lsd_call_example: lsd.c lsd.h lsd_call_example.c
cl -o lsd_call_example lsd_call_example.c lsd.c -lm doc: lsd.c lsd.h doxygen.config
doxygen doxygen.config clean:
rm -f lsd lsd_call_example cleandoc:
rm -rf doc # -----------------------------------------------------------------------------

接着使用编译命令:

nmake -f Makefile1

就这样编译通过了:

 D:\GitHub\lsd_1.>nmake -f Makefile1

 Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation. All rights reserved. cl -O3 -o lsd lsd_cmd.c lsd.c -lm
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved. cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
cl : Command line warning D9002 : ignoring unknown option '-O3'
cl : Command line warning D9002 : ignoring unknown option '-lm'
lsd_cmd.c
lsd.c
Generating Code...
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved. /out:lsd_cmd.exe
/out:lsd.exe
lsd_cmd.obj
lsd.obj
cl -o lsd_call_example lsd_call_example.c lsd.c -lm
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved. cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
cl : Command line warning D9002 : ignoring unknown option '-lm'
lsd_call_example.c
lsd.c
Generating Code...
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved. /out:lsd_call_example.exe
/out:lsd_call_example.exe
lsd_call_example.obj
lsd.obj

注意:其实makefile中应该还有其他需要修改的,但是简单编译一个exe已经实现了,至于其他需要修改的有时间再研究。

Windows使用nmake和Makefile编译c++的更多相关文章

  1. windows下如何使用makefile编译

    1. 编写makefile. 2. 使用nmake进行编译, vs2010或者其他都是用nmake进行编译的,将bin目录添加到path环境变量中 先执行vcvars32.bat 再执行nmake

  2. 在 Windows下用 Visual Studio 编译 OpenSSL 1.1.0

    到OpenSSL官方网站下载OpenSSL源代码包 1.下载 openssl-1.1.0.tar.gz 2.安装 ActivePerl, 可以到http://www.activestate.com/a ...

  3. Win7 + VS2015 + CMake3.6.1-GUI + Makefile 编译开源库

    CMake生成Unicode版本VC工程 Just add this line in your top CMakeLists.txt file:     add_definitions(-DUNICO ...

  4. 【VS开发】【数据库开发】libevent windows下基于VS2010的编译

    libevent是一个常用的网络库,下面就看看在windows下面编译测试的过程吧. 一 环境 系统:win8.1编译器:VS2013官方下载地址:http://libevent.org/版本:2.0 ...

  5. Windows 内核(WRK)编译

    引子 WRK 是微软于 2006 年针对教育和学术界开放的 Windows 内核的部分源码, WRK(Windows Research Kernel)也就是 Windows 研究内核, 在 WRK 中 ...

  6. VS环境下的makefile编译

    直接找这个了,原来VS也可以makefile,在windows上解析makefile的软件叫NMAKE.exe 打算用命令Cmake -G“NMake Makefiles” 生成VS环境下Nmake的 ...

  7. VS2005环境下采用makefile编译、使用libjpeg.lib函数库

    1.从www.ijg.org下载源码,解压后得到文件夹jpeg-8d 2.在文件夹里新建jconfig.h文件,将jconfig.vc里的内容拷到jconfig.h中 3.编译. Run->CM ...

  8. libevent在windows下用visual studio编译时出现error C2894错误的原因与解决方法

    libevent是一个使用很广泛的网络库,今天想了解下它.于是去git clone了一份源码,用vs2005的命令行:nmake -f makefile.nmake编译之,顺利编译通过,生成三个静态库 ...

  9. 手动写Makefile编译Android NDK的so

    之所以摒弃NDK,是因为NDK编译出来的so太大,而且导出表总有一些没用的符号.而且手动编译的话,可以得到编译过程中间的.i和.s文件,可以删除一些没用的汇编代码.现在代码列出来:我的NDK C的代码 ...

随机推荐

  1. 在vue项目中设置BASE_URL

    在vue项目中设置BASE_URL 1.在config文件夹中新建global.js文件 const BASE_URL = 'http://192.168.1.62:8080/rest/' expor ...

  2. eclipse将项目打包成jar在linux中运行

    最近因为项目需要,做了几个外挂程序做数据传输,涉及到项目打包操作,在此记录一下打包步骤和其中出现的问题. 1.首先右键项目文件夹,点击export,弹出如下选择框,在其中输入jar搜索,并选择JAR ...

  3. [AHOI2002] 芝麻开门 - 数论

    求 \(n^k\) 的因子和, \(n \leq 2^{16}, k \leq 20\) Solution \[\prod_i \frac{p_i^{q_ik+1}-1}{p_i-1}\] #incl ...

  4. localStorage存、取数组

    localStorage存储数组时需要先使用JSON.stringify()转成字符串,取的时候再字符串转数组JSON.parse(). var arr=[1,2,3,4]; localStorage ...

  5. Alan Walker MV 合辑01 by defender 歌词

    其实是歌词浏览,配套Alan Walker MV 合辑01 by defender You were the shadow to my life Did you feel us Another sta ...

  6. react 渲染

    目录 React渲染 createElement的三个参数 element如何生成真实节点 ReactDOMComponent 作用 ReactCompositeComponentWrapper 作用 ...

  7. Python之tcp server模拟Http通信

    1.python tcp server代码: import socket def main(): tcp_server_socket = socket.socket(socket.AF_INET, s ...

  8. Django---Django初始

    现在测试行业慢慢的也需要存在代码能力了,从以前的点点点到通过工具进行测试接口,到目前的自动化测试,需要测试会代码的越来越多了.慢慢的测试开发这一行业出现在我们的面前,测试不仅仅会点点,还能自己帮助开发 ...

  9. 腾讯短链接url生成接口/腾讯短网址在线生成/新浪微博短链接生成器的分享

    在通常情况下,URL是由系统生成的,通常包括URI路径,多个查询参数,可以对参数进行加密和解密. 当人们要分享某个URL,比如短信,邮件,社交媒体,这就需要短URL.而短网址,顾名思义就是在长度上比较 ...

  10. SPDK-nvmf与不同传输类型的公共接口

    SPDK-nvmf与不同传输类型的公共接口 不同类型的传输层到nvmf的公共命令请求接口 nvmf_fc_hwqp_handle_request() -->cmd_iu = buffer-> ...