Windows使用nmake和Makefile编译c++
今天在本地看到一个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++的更多相关文章
- windows下如何使用makefile编译
1. 编写makefile. 2. 使用nmake进行编译, vs2010或者其他都是用nmake进行编译的,将bin目录添加到path环境变量中 先执行vcvars32.bat 再执行nmake
- 在 Windows下用 Visual Studio 编译 OpenSSL 1.1.0
到OpenSSL官方网站下载OpenSSL源代码包 1.下载 openssl-1.1.0.tar.gz 2.安装 ActivePerl, 可以到http://www.activestate.com/a ...
- Win7 + VS2015 + CMake3.6.1-GUI + Makefile 编译开源库
CMake生成Unicode版本VC工程 Just add this line in your top CMakeLists.txt file: add_definitions(-DUNICO ...
- 【VS开发】【数据库开发】libevent windows下基于VS2010的编译
libevent是一个常用的网络库,下面就看看在windows下面编译测试的过程吧. 一 环境 系统:win8.1编译器:VS2013官方下载地址:http://libevent.org/版本:2.0 ...
- Windows 内核(WRK)编译
引子 WRK 是微软于 2006 年针对教育和学术界开放的 Windows 内核的部分源码, WRK(Windows Research Kernel)也就是 Windows 研究内核, 在 WRK 中 ...
- VS环境下的makefile编译
直接找这个了,原来VS也可以makefile,在windows上解析makefile的软件叫NMAKE.exe 打算用命令Cmake -G“NMake Makefiles” 生成VS环境下Nmake的 ...
- VS2005环境下采用makefile编译、使用libjpeg.lib函数库
1.从www.ijg.org下载源码,解压后得到文件夹jpeg-8d 2.在文件夹里新建jconfig.h文件,将jconfig.vc里的内容拷到jconfig.h中 3.编译. Run->CM ...
- libevent在windows下用visual studio编译时出现error C2894错误的原因与解决方法
libevent是一个使用很广泛的网络库,今天想了解下它.于是去git clone了一份源码,用vs2005的命令行:nmake -f makefile.nmake编译之,顺利编译通过,生成三个静态库 ...
- 手动写Makefile编译Android NDK的so
之所以摒弃NDK,是因为NDK编译出来的so太大,而且导出表总有一些没用的符号.而且手动编译的话,可以得到编译过程中间的.i和.s文件,可以删除一些没用的汇编代码.现在代码列出来:我的NDK C的代码 ...
随机推荐
- 用数学解赌博问题不稀奇,用赌博解数学问题才牛B
有一个经典的概率问题:平均需要抛掷多少次硬币,才会首次出现连续的 n 个正面?它的答案是 2^(n+1) – 2 .取 n=2 的话,我们就有这样的结论:平均要抛掷 6 次硬币,才能得到两个连续的正面 ...
- 题解【AcWing883】高斯消元解线性方程组
题面 高斯消元模板题. 这里直接讲述一下高斯消元的算法流程: 枚举每一列 \(c\): 找到第 \(c\) 列绝对值最大的一行: 将这一行换到最上面: 将该行的第一个数变成 \(1\): 将下面所有行 ...
- eclipse 项目的创建 编写 'Hello World'
写项目之前确保 eclipse 安装完成 以及JDK 环境配置 成功 开始: 打开eclipse 右键file ->new->java project 如图: 然后输入项目名 点击Fin ...
- 【C语言】【欢哥TV】冒泡法排序视频演示
fromB站 点击进入:Go
- 改变容器Size后,刷新地图大小。
You need to call the API to update map size. http://dev.openlayers.org/docs/files/OpenLayers/Map-js. ...
- python笔记20(面向对象课程二)
今日内容 类成员 成员修饰符 内容回顾 & 补充 三大特性 封装 函数封装到类 数据封装到对象 * class Foo: def __init__(self,name,age): self.n ...
- Django文件夹
Django文件 App文件夹 migrations文件 生成models创建表的翻译语句 telemplatetags文件夹 telemplatetags文件夹下的文件专门用来创建自定义标签.自定义 ...
- 解决 IDEA 无法提示导入 java.util.Date 的问题
之前有一段时间在使用IDEA的时候,发现通过快捷键Alt + Enter导入并没有提示有java.util.Date的包,仅仅只有java.sql.Date的包.于是每次使用都需要通过手写import ...
- 杭电oj————2057(java)
question:A+ B again 思路:额,没啥思路/捂脸,用java的long包里的方法,很简单,只是有几次WA,有几点要注意一下 注意:如果数字有加号要删除掉,这里用到了正则表达式“\\+” ...
- onvif学习一:wsdl 和soap
来源:https://www.cnblogs.com/huanghongbo/p/5920123.html WSDL是用来描述WebService的,它用XML的格式描述了WebService有哪些方 ...