CMake with Win&MinGW

  今天一个下午都在做一件简直耻辱play的事情,论文没看,程序没写,玩了一个下午的编译器。。。心塞(逃。。。

  言归正传,今天要讲在windows下,使用Cmake和MInGW.

 1.g++

  MinGW的安装需要首先下载安装器

  然后将安装目录设置成环境变量,以便于cmd在任何目录下都能调用里面的程序。

  在安装完成后,在cmd中依次执行:

mingw-get install gcc
mingw-get install g++
mingw-get install gdb
 
效果大概是下面这样:
F:\C++\cmake\source>g++ main.c -o hello

F:\C++\cmake\source>ls
CMakeLists.txt  bin  hello.exe  main.c

F:\C++\cmake\source>hello.exe
Hello World!/n

如果你足够细心会发现一个神奇的语句:ls

显然windows的shell是不支持这个语句的,这个功能属于MinGW的副产品。

在安装gcc的时候,不知道怎么还安装了一个msys的文件夹。顺手把它包含到系统环境变量Path中,windows的shell就支持linux的语句了。

至此为止,我们可以使用g++工具编译helloworld了,但是。。。。也就能写个helloworld一类的程序吧。。。。。

2.CMake

  其实我对CMake并不陌生,最早相识于PCL,后来也用它配置过OpenCV,再后来还配置过VTK,QT。我真没想到今天在CMake翻了船搞了一下午。。。。。

  起因是这样的,像往常一样写好source file.cpp 和 CMakeLists.txt,然后调CMake对程序进行构建,为了能让构建能和ST3尽量符合,我选了之前安装的MinGW作为编译器,而不是以vs2010作为构建输出结果。结果是这样的。。。

F:.
└─source
    └─bin
        └─CMakeFiles
//这是我的文件结构,source 文件夹下放有源文件。我在bin下执行的cmake
F:\C++\cmake\source\bin>cmake .. -G"MinGW Makefiles"

CMake Error: CMake was unable to find a build program corresponding to "MinGW Ma
kefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a differe
nt build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Ma
kefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a differe
nt build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

0.0居然报错了。。。。好像说MinGW的makefiles有点问题,上SS一查,好像是没装make。

WTF,make不是应该和gcc在一起的么,怎么还要单独安装,结果跑去SF一看,还真是单独的。。

那赶紧下一个然后解压合并到 C:\MinGW 里去。这里是下载地址

ok,然后再重新使用cmake来构建,结果如下:

F:\C++\cmake\source\bin>cmake .. -G"MinGW Makefiles"
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: F:/C++/cmake/source/bin

F:\C++\cmake\source\bin>make
Scanning dependencies of target hello
[ 50%] Building C object CMakeFiles/hello.dir/main.c.obj
[100%] Linking C executable hello.exe
[100%] Built target hello

F:\C++\cmake\source\bin>hello.exe
Hello World!/n

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值