CMake和Linux编程:find_package的使用

时间:2022-04-05 14:35:10

1.第一个CMake例子

  在 t1 目录建立 main.c 和 CMakeLists.txt(注意文件名大小写):
  main.c 文件内容:

//main.c
#include <stdio.h>
int main()
{
printf(“Hello World from t1 Main!n”);
return 0;
}

 CmakeLists.txt 文件内容:

PROJECT (HELLO)
SET(SRC_LIST main.c)
MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ${SRC_LIST})
 PROJECT (HELLO)
SET(SRC_LIST main.c)
MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello SRC_LIST)

2.第二个CMake例子

CmakeLists.txt 文件内容:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(normal_distributions_transform)
FIND_PACKAGE(PCL 1.8 REQUIRED) include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS}) add_executable(normal_distributions_transform normal_distributions_transform.cpp )
target_link_libraries (normal_distributions_transform ${PCL_LIBRARIES})

参考资料:

find_package与CMake如何查找链接库详解

CMake如何查找链接库---find_package的使用方法

CMake中find_package功能演示

Cmake中的find_package功能


深入讲解GCC和Make的区别

知乎:GCC 和 cmake的关系?

CMake 入门实战

linux中cmake语法的学习

《CMake实践》笔记