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的代码 ...
随机推荐
- [Agc081F/At2699] Flip and Rectangles - 单调栈,结论
[Agc081F/At2699] 给出一个拥有 \(H\times W\) 个格子的棋盘,每个格子的颜色为黑色或白色. Snuke 可以进行任意次下列操作: 选择棋盘中的一行或一列,将这一行或一列的颜 ...
- phpstorm对比代码
方法一 首先在phpstorm中左侧的资源管理器中,按住键盘上的CTRL键选中两个文件,然后鼠标右键,点击菜单中的"Compare Tow Files",就可以了,如下图 方法二 ...
- linux - mysql - 卸载:RPM包安装方式的MySQL卸载
(1)检查是否安装了MySQL组件 [root@DB-Server init.d]# rpm -qa | grep -i mysql MySQL-devel-5.6.23-1.linux_glibc2 ...
- Python中读取目录里的文件并按排序列出
1.os.listdir():用于返回指定的文件夹包含的文件或文件夹的名字的列表. 如: dir ='F:/Home_01/img'#当前目录 filenames=os.listdir(dir)#fi ...
- 记录 shell学习过程(5)continue break
1.continue ;i<;i++)) do ];then continue fi echo $i done # ./continue.sh12346789 2.break ;i<;i+ ...
- CSS的长度单位
对于css的长度单位真的有必要知道一下.那么css长度单位有哪些呢? 分成两大类: 1.绝对单位:不会因为其他元素的尺寸变化而变化.坚持自我. 2.相对单位:没有一个确定的值,而是由其他元素的尺寸影响 ...
- python之pandas简介
一. Pandas简介 1.Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和 ...
- 关于spring boot集成MQTT
安装 说到mqtt,首先肯定要安装了,安装什么的地址:http://activemq.apache.org/ap...我本地是Windows的环境,所以装的是Windows版本,这里是第一个注意的地方 ...
- Flink系统配置
Flink 系统配置 Flink 提供了多个配置参数,用于调整Flink的行为与性能,所有参数均在flink-config.yaml 文件中.下面我们介绍一下几个主要配置. Java and Clas ...
- ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. 解决方案: 异步更新 ...