zoukankan      html  css  js  c++  java
  • 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++cmakesource>g++ main.c -o hello
    
    F:C++cmakesource>ls
    CMakeLists.txt  bin  hello.exe  main.c
    
    F:C++cmakesource>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++cmakesourcein>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++cmakesourcein>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++cmakesourcein>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++cmakesourcein>hello.exe
    Hello World!/n
  • 相关阅读:
    整系数多项式的有理根的一个性质
    整系数多项式的有理根的一个性质
    《陶哲轩实分析》——给读者的一点建议
    《陶哲轩实分析》——给读者的一点建议
    不要把时间浪费在QQ上
    整系数多项式的整除平移不变性
    在Ubuntu上安装MATLAB
    边缘AI方案落地问题探讨
    主干开发前要知道的,4错误认识+3优势
    有了这个告警系统,DBA提前预警不是难题
  • 原文地址:https://www.cnblogs.com/ironstark/p/5033856.html
Copyright © 2011-2022 走看看