linux下cmake图形配置,Linux cmake安装,配置以及测试-Go语言中文社区

安装

cmake-3.2.2.tar.gz

解压:tar zxvf cmake-3.2.2.tar.gz 得到 cmake-3.2.2

进入cmake-3.2.2:cd cmake-3.2.2

./bootstrap --prefix=/home/zj/cmake_install

#prefix后跟安装目录

make

make install

配置

vi /etc/profile

在文件的最后一行加入

export PATH=目录/cmake-build-3.2.2/bin:$PATH

#目录意思是cmake-build-3.2.2的绝对地址

保存退出后

source /etc/profile

验证

cmake --version

出现版本号则为成功

######################################

解压cmake.tar.gz后,在其中找到README.rst,里面有安装的过程:

UNIX/Mac OSX/MinGW/MSYS/Cygwin

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You need to have a compiler and a make installed.

Run the ``bootstrap`` script you find the in the source directory of CMake.

You can use the ``--help`` option to see the supported options.

You may use the ``--prefix=`` option to specify a custom

installation directory for CMake. You can run the ``bootstrap`` script from

within the CMake source directory or any other build directory of your

choice. Once this has finished successfully, run ``make`` and

``make install``. In summary::

$ ./bootstrap && make && make install

但是我安装上面安装完成后,如果不加环境变量到PATH,则没有安装成功。

我在下面的网页上找到除上面外第二种方法:

添加环境变量CMAKE_ROOT,格式如下:

export CMAKE_ROOT=/home/zj/cmake_install/share/cmake3.2

其中share目录和bin目录属于同一等级(个人理解,是在同一目录下)

a9b9b4021fe107ece6d35d8e9a99916e.png

#########################################################3

cmake测试

测试一:

新建文件夹cmake_demo1

进入cmake_demo1,新建文件main.cpp:

#include

int main()

{

std::cout<

return 0;

}

新建文件CMakeLists.txt:

PROJECT(main)

CMAKE_MINIMUM_REQUIRED(VERSION 3.2.2)

AUX_SOURCE_DIRECTORY(. DIR_SRCS)

ADD_EXECUTABLE(main ${DIR_SRCS})

执行命令:

cmake .

make

完成后,即出现main可执行文件,运行

fcf777677d6e8dc0a2aca78f387c01e1.png

测试二:

要求已安装opencv

新建文件加cmake_demo2

进入cmake_demo2,新建文件test.cpp:

#include

#include

using namespace cv;

int main(int argc, char* argv[])

{

Mat image;

image = imread(argv[1], 1);

if (argc != 2 || !image.data)

{

printf("No image datan");

scanf("%d", &argc);

return -1;

}

namedWindow("Display Image", CV_WINDOW_AUTOSIZE);

imshow("Display Image", image);

waitKey(0);

return 0;

}

新建文件CMakeLists.txt:

project(test)

find_package(OpenCV REQUIRED)

add_executable(test test)

target_link_libraries(test ${OpenCV_LIBS})

cmake_minimum_required(VERSION 3.2.2)

运行命令:

cmake .

make

完成后,出现test可执行文件:

27f2dc4cdbef47fe23929f368327ffa0.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值