Linux cmake安装,配置以及测试

安装

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=<install_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,则没有安装成功。

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

http://stackoverflow.com/questions/18615451/cmake-missing-modules-directory


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

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

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




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


cmake测试


参考:http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/

测试一:

新建文件夹cmake_demo1

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

#include <iostream>

int main()
{
	std::cout<<"Hello World!!!"<<std::endl;

	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可执行文件,运行



参考:http://my.oschina.net/u/1757926/blog/293976

测试二:

要求已安装opencv

新建文件加cmake_demo2

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

#include <cv.h>  
#include <highgui.h>  
  
using namespace cv;  
  
int main(int argc, char* argv[])  
{  
    Mat image;  
    image = imread(argv[1], 1);  
  
    if (argc != 2 || !image.data)   
    {  
        printf("No image data\n");
	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可执行文件:




©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页