Mac CMake安装和使用

来源:互联网 发布:新开的淘宝店怎么经营 编辑:程序博客网 时间:2024/05/16 11:17


Mac CMake安装和使用

一、安装

1、   下载地址:https://cmake.org/download/

2、   LZ:MacOS Sierra 10.12.5

3、   下载后,按照指示安装完。

二、使用:”HELLO WORLD”

1、   随便建个文件夹,命名为HELLO

2、   新建三个

1)           main.c:

#include<stdio.h>

int main(void)

{

printf("Hello,World\n");

return 0;

}

2)           CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION2.6) #cmake最低版本需求,不加入此行会受到警告信息

PROJECT(HELLO) #项目名称  

AUX_SOURCE_DIRECTORY(.SRC_LIST) #把当前目录(.)下所有源代码文件和头文件加入变量SRC_LIST

ADD_EXECUTABLE(hello${SRC_LIST}) #生成应用程序 hello (在windows下会自动生成hello.exe)

3)           Build

【空目录

3、   编译项目

1)   命令行

a) 进入空目录build

muaxiu@muaxiu:~/Desktop/HELLO/build|

  ls

b)cmake ..

muaxiu@muaxiu:~/Desktop/HELLO/build|

  cmake ..

--The C compiler identification is AppleClang 8.1.0.8020042

--The CXX compiler identification is AppleClang 8.1.0.8020042

--Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc

--Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc --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: /Library/Developer/CommandLineTools/usr/bin/c++

--Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++-- 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:/Users/muaxiu/Desktop/HELLO/build

注:如果出现“CMake not found”

exportPATH=/Applications/CMake.app/Contents/bin:$PATH

“/Applications/CMake.app/Contents/bin”根据自己的文件目录更改

muaxiu@muaxiu:~|  exportPATH=/Applications/CMake.app/Contents/bin:$PATH

muaxiu@muaxiu:~|  which CMake                                          

/Applications/CMake.app/Contents/bin/CMake

这时,which CMake终端就可以找到CMake了

c)make

  make

Scanningdependencies of target hello

[50%] Building C objectCMakeFiles/hello.dir/main.c.o

[100%]Linking C executable hello

[100%] Built target hello

d)现在build目录下就有很多东西了

  ls

CMakeCache.txt      Makefile            hello

CMakeFiles          cmake_install.cmake

e)./hello

  ./hello

Hello,World

2)   图形界面

a)根据自己的路径对号入座


b)点击configure



c)Configure完了以后,选项可能为红色,重复按Configure命令,直到所有的红色选项都变成灰色为止,最后再按Generate命令。


d)

 

 

 

参考:http://www.cnblogs.com/hoojjack/p/3849537.html


原创粉丝点击