Methods for importing third party libraries using CMake in Clion

Source: Internet
Author: User

https://blog.csdn.net/Haoran823/article/details/71657602

methods for importing third party libraries using CMake in Clion

Recently tried using the Clion IDE to write C + + programs. Because Clion engineering is built on CMake, importing a third-party library requires configuration in CMake files. The process of using CMake to import a Third-party library is documented here.

The configuration information for CMake is written in the CMakeList.txt file. In the CMakeList.txt file, we first define two variables Inc_dir and Link_dir, which represent the header file path and the path to the library. Here, for example, I put the Wfdb library under the downloads file as follows:

Set (Inc_dir/users/haoran/downloads/wfdb/include)
set (Link_dir/users/haoran/downloads/wfdb/lib)
1 2

Then set the header file directory, the library directory, and the library to be linked in turn, as follows:

Include_directories (${inc_dir})
link_directories (${link_dir})
link_libraries (WFDB)
1 2 3

Note that the above code must be placed before the add_executable statement, and the next link library operation must be placed after the add_executable statement.

Use the following statement to complete the link operation of the library:

Target_link_libraries (Wfdb_demo wfdb)
1

The Wfdb_demo in parentheses is the project name, Wfdb is the name of the library.

So far we have completed the link process for the third party library.

As a reference, the complete CMake code for this project is as follows:

Cmake_minimum_required (VERSION 3.6)
project (Wfdb_demo)

set (Cmake_cxx_standard)

set (source_files main.cpp)

Set (Inc_dir/users/haoran/downloads/wfdb/include)
set (link_dir/users/haoran/downloads/wfdb/ LIB)

include_directories (${inc_dir})
link_directories (${link_dir})
link_libraries (wfdb)

add_ Executable (Wfdb_demo ${source_files})
target_link_libraries (Wfdb_demo wfdb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Copyright Disclaimer: This article is the original article for big fan Mao, not allowed to reprint without permission. https://blog.csdn.net/Haoran823/article/details/71657602 Article Tags: library cmake clion C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.