Detailed explanation of several ways to install CMake on Ubuntu

Detailed explanation of several ways to install CMake on Ubuntu

apt install CMake

sudo apt install cmake

This method is easy to install, but the disadvantage is that if you want to cross-compile opencv for the Android platform yourself, you will be prompted that the version is too low, because the cmake version in the ubuntu16.04 source is only 3.5.1, and the Android cross-compilation toolchain android.toolchain.cmake requires a minimum cmake version of 3.6.0

Download source code and compile CMake

Go to the cmake official website to download the latest cmake

https://cmake.org/download/

After downloading, unzip it and then enter the directory and execute:

./bootstrap
make -j8
sudo make install

Verify version

cmake --version
cmake version 3.9.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).

This method can install the latest version of cmake, but if you want to cross-compile a third-party library for the Android platform, there will be problems during compilation, because the cross-compilation toolchain android.toolchain.cmake provided in the Android Sdk does not support the latest version of cmake

Soft link CMake in Android Sdk

Soft link the cmake in Android Sdk to the /usr/local/bin directory

sudo ln -s /home/gavinandre/Android/Sdk/cmake/3.6.4111459/bin/cmake /usr/local/bin

Now there should be no problem using the android cross-compilation toolchain android.toolchain.cmake to compile some third-party libraries

Write a simple Cmake example

First we write a main.cpp file, a simple helloworld program

#include<iostream>
int main()
{
  std::cout<<"hello world!"<<std::endl;
  return 0;
}

Then write the CMakeLists.txt file

cmake_minimum_required(VERSION 2.8)
#Project nameproject(HELLOWORLD)
#Include the original program, that is, copy the source program in the given directory to the variable DIR_SRC
#Store the source files in the specified path in the specified variable aux_source_directory(./DIR_SRC)
#Generate program add_executable(helloworld ${DIR_SRC})

Compile

$ mkdir build
$ cd build
$cmake ..
$make
$ ./helloworld

Execution Result:

hello world!

This is the end of this article about several ways to install CMake on Ubuntu. For more information about installing CMake on Ubuntu, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Installation and use of ubuntu14.04+docker
  • How to Install Nginx Server on Ubuntu
  • Installation, update, deletion and simple use of snap packages in Ubuntu
  • Things to do after installing Ubuntu 16.04 (Summary)
  • Tutorial on installing MariaDB database in Ubuntu system
  • Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
  • Experience sharing of installing Eclipse under Ubuntu 14.04
  • Full record of Ubuntu 16.04 installation process
  • Steps to install pycharm on Ubuntu 14.04
  • Installation and use of Thunder Speed ​​​​Edition under Ubuntu

<<:  How to elegantly back up MySQL account information

>>:  Writing tab effects with JS

Recommend

Detailed explanation of the new array methods in JavaScript es6

Table of contents 1. forEach() 2. arr.filter() 3....

Solution to garbled display of Linux SecureCRT

Let's take a look at the situation where Secu...

Detailed explanation of MySQL date addition and subtraction functions

1. addtime() Add the specified number of seconds ...

How to implement mask layer in HTML How to use mask layer in HTML

Using mask layers in web pages can prevent repeat...

MySQL master-slave synchronization principle and application

Table of contents 1. Master-slave synchronization...

What to do if the online MySQL auto-increment ID is exhausted

Table of contents Table definition auto-increment...

Introduction to Sublime Text 2, a web front-end tool

Sublime Text 2 is a lightweight, simple, efficien...

Analyze how a SQL query statement is executed in MySQL

Table of contents 1. Overview of MySQL Logical Ar...

Simple example of adding and removing HTML nodes

<br />Simple example of adding and removing ...

JavaScript Canvas draws dynamic wireframe effect

This article shares the specific code of JavaScri...

MySQL data compression performance comparison details

Table of contents 1. Test environment 1.1 Hardwar...

Html tips to make your code semantic

Html semantics seems to be a commonplace issue. G...

Summary of Linux file directory management commands

touch Command It has two functions: one is to upd...

How to find the specified content of a large file in Linux

Think big and small, then redirect. Sometimes Lin...