Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ CMake Quick Start Tutorial     - CentOS7 install JDK (Linux)

- RHEL5.8 physical opportunities to Read-only file system (Linux)

- Oracle 11g statistics collection - collection of multi-column statistics (Database)

- Bash mathematical extension (Programming)

- Six Ways to view slides can be implemented Android (Programming)

- The sublime into IDE (Linux)

- Realization of Linux operating system illegal IP censorship (Linux)

- Linux file and directory management - ls, cp, mv (Linux)

- Linux Getting Started tutorial: XWindow what (Linux)

- Vi editor Introduction (Linux)

- Ubuntu 15.04 and Ubuntu 14.04 installed Cinnamon 2.6 (Linux)

- Linux install Samba file sharing server (Server)

- Troubleshooting Linux virtual machine device id and the letter of inconsistencies (Linux)

- Git bulk delete remote tag (Linux)

- crontab cause CPU exception Analysis and Processing (Linux)

- netfilter- in kernel mode network packet operation (Linux)

- Linux excellent text editor (Markdown, LaTeX, MathJax) (Linux)

- Linux System Getting Started Learning: Disable HTTP forwarding wget in (Linux)

- Import and export myloader accelerate mydumper (Database)

- After installing minimize RHEL / CentOS 7 we need to do (Linux)

  CMake Quick Start Tutorial
  Add Date : 2017-01-08      
  If you feel a headache looking at the makefile, if and when the project is growing, more and more you know what to do, if you're tired at compile time marked with a lot of command, then you need to spend ten minutes a look at the following content .

First, HelloWorld

First create a folder test1, which create a main.c file, as follows:

#include < stdio.h >
int main ()
 printf ( "! Hello World \ n");
 return 0;

Create a CMakeLists.txt

SET (SRC_LIST main.c)

First line: the item name;

Second row: the setting value main.c SRC_LIST

Third row: an executable file hello. $ {} Is a reference value.

Terminal in cd into test1 directory, create a directory for external build build (compiled files generated are generated in the build directory), followed by implementation of the following three commands:

cmake ..

The results obtained are as follows:

If you want to quote the words of the internal libraries, such as about the SDL and opengl procedures, the need to add CMakeLists.txt


Compile the corresponding terminal command is:


If it were not cited internal library, you'll need to add in the appropriate directory, it is used INCLUDE_DIRECTORIES command.

Second, the construction and installation of the library

Our goal is this:

1, the establishment of a static and dynamic library provides functions for other programming HelloFunc use, HelloFunc to the output terminal

Hello World string.

2. Install header files and shared libraries.

Directory is organized as follows:

build- for external compiler;

libhello-hello library source files;

src- main

First look libhello in the file:

void hello (const char * name);
#endif // DBZHANG_HELLO_

#include < stdio.h >
#include "hello.h"

void hello (const char * name)
    printf ( "Hello% s \ n!", name);


cmake_minimum_required (VERSION 2.8)
set (LIB_SRC hello.c)
add_library (libhello STATIC $ {LIB_SRC})
set_target_properties (libhello PROPERTIES OUTPUT_NAME "hello")
install (TARGETS libhello
install (FILES hello.h DESTINATION include / hello)

src folder

#include "hello.h"
int main ()
    hello ( "Jack");
    return 0;


cmake_minimum_required (VERSION 2.8)
include_directories ($ {PROJECT_SOURCE_DIR} / libhello)
set (APP_SRC main.c)
add_executable (main $ {APP_SRC})
target_link_libraries (main libhello)

Outermost CMakeLists.txt

project (HELLO)
add_subdirectory (src)
add_subdirectory (libhello)


In addition to a build directory outside of each directory should build a CMakeLists.txt.

Statement generates library: add_library (libhello STATIC $ {LIB_SRC})

This statement is to create a static library, to create a dynamic library, then into the STATIC SHARED.

install command responsible for the installation of the library.

make, the result looks like this:

Then sudo make install.

After installing the library, we want to use the hello method, as long as you can add #include header files, and compile time

g ++ main .c -o main -lhello

We can cite a compiled library.
- Ubuntu users to install the system indicator SysPeek 0.3 (Linux)
- Timeout control related to Python threads and a simple application (Programming)
- Ubuntu 14.04 Install WordPress on Nginx (Server)
- Java List add duplicate the same object (Programming)
- Ubuntu / openSUSE users to install Veusz 1.21.1 (Linux)
- Ubuntu 10.10 install Oracle 10g Installation Guide (Database)
- Adjustment expand VMDK format VirtualBox disk space (Linux)
- Installation Elementary OS Freya 20 things to do (Linux)
- Java implementation linear table - represents the order of representation and chain (Programming)
- Nginx Performance Tuning Guidelines (Server)
- Linux systems for entry-learning - Install Go language in Linux (Linux)
- Ubuntu 14.04 can be used to create a WIFI hotspot for Android (Linux)
- ARM platform compiler installation Golang (Linux)
- 10046 trace only open for a particular SQL statement (Database)
- File compression and packaging commands under Linux (Linux)
- Four IDS intrusion detection tool under Linux environment (Linux)
- MySQL master-slave database configuration and error handling Raiders (Database)
- Linux Bash share tips for getting started (Linux)
- To install Scribus 1.4.4 under ubuntu (Linux)
- Depth understanding of the TCP protocol (Database)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.