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 + +