一个C++工程,名为surfaceDeformation,依赖PCL、Eigen3、Boost、VTK、Qhull与CGAL库,如何编写其CMakeLists,完成该C++项目的编译,同时将其编译为动态链接库?在Linux系统中
时间: 2023-12-14 12:35:40 浏览: 110
以下是一个可能的 CMakeLists.txt 文件示例,可供参考:
```cmake
cmake_minimum_required(VERSION 3.5)
project(surfaceDeformation)
# 设置编译类型为 Release
set(CMAKE_BUILD_TYPE "Release")
# 设置 C++ 标准为 C++11
set(CMAKE_CXX_STANDARD 11)
# 添加依赖库
find_package(PCL REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Boost REQUIRED)
find_package(VTK REQUIRED)
find_package(CGAL REQUIRED)
include(${CGAL_USE_FILE})
# 添加头文件路径
include_directories(
include
${PCL_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${VTK_INCLUDE_DIRS}
${CGAL_INCLUDE_DIRS}
)
# 添加库文件路径
link_directories(
${PCL_LIBRARY_DIRS}
${VTK_LIBRARY_DIRS}
)
# 添加源文件
set(SRC_FILES
src/main.cpp
src/surface_deformation.cpp
)
# 生成动态链接库
add_library(surfaceDeformation SHARED ${SRC_FILES})
# 链接依赖库
target_link_libraries(surfaceDeformation
${PCL_LIBRARIES}
${Boost_LIBRARIES}
${VTK_LIBRARIES}
${CGAL_LIBRARIES}
)
# 安装目标文件和头文件
install(TARGETS surfaceDeformation DESTINATION lib)
install(FILES include/surface_deformation.h DESTINATION include)
```
在项目根目录下创建一个 build 文件夹,进入该文件夹,并执行以下命令:
```bash
cmake ..
make
sudo make install
```
这将会编译并安装动态链接库文件和头文件到系统中。
阅读全文