当前位置: 首页 > 工具软件 > Linx > 使用案例 >

linx make install

琴宾鸿
2023-12-01

问题概述

正常情况拿到一个新的cpp库,可以用以下三连操作完成安装

mkdir build
cd build
cmake ../
make
sudo make install

我需要安装A库,并在B库make中导入A库,但今天我没有sudo权限,因此最后一步无法执行。

解决过程

  • 安装A库
    因为没有sudo权限,所以使用以下语句把A库强迫安装在目录your_path
make install DESTDIR=/your_path
  • make B库
    B库原本的CMakeLists.txt如下所示,他会在/usr/local/下面找
cmake_minimum_required(VERSION 2.8.3)
project(unitree_legged_sdk)

include_directories(include)

link_directories(lib)

add_compile_options(-std=c++11)

set(EXTRA_LIBS -pthread libunitree_legged_sdk_amd64.so lcm)

set(CMAKE_CXX_FLAGS "-O3")

add_subdirectory(pybind11)
pybind11_add_module(robot_interface python_interface.cpp)
target_link_libraries(robot_interface ${EXTRA_LIBS})
  • 改进,让程序到your_path寻找lcm这个包,其中your_path下必须存lcmConfig.cmake文件(该文件在make install 库A 时已经产生)
cmake_minimum_required(VERSION 2.8.3)

project(unitree_legged_sdk)

include_directories(include)

link_directories(lib)

add_compile_options(-std=c++11)

set(lcm_DIR "your_path")

find_package(lcm REQUIRED)

set(EXTRA_LIBS -pthread libunitree_legged_sdk_amd64.so lcm)

set(CMAKE_CXX_FLAGS "-O3")

add_subdirectory(pybind11)

pybind11_add_module(robot_interface python_interface.cpp)

target_link_libraries(robot_interface PRIVATE ${EXTRA_LIBS})

Linux编译知识简介

cmake, makefile.txt, make关系简介 : 对于make与cmake的关系简单理解

cmake 简单示例 : 很好很简洁的一个cmake样例

find_package

debug过程

  • CMakeLists.txt文件中输出变量值用以debug
MESSAGE (STATUS "${lcm_FOUND}")
  • 报错

原语句

target_link_libraries(robot_interface ${EXTRA_LIBS})

报错内容

CMake Warning (dev) at CMakeLists.txt:19 (target_link_libraries):
  Policy CMP0023 is not set: Plain and keyword target_link_libraries
  signatures cannot be mixed.  Run "cmake --help-policy CMP0023" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  The keyword signature for target_link_libraries has already been used with
  the target "robot_interface".  All uses of target_link_libraries with a
  target should be either all-keyword or all-plain.

  The uses of the keyword signature are here:

   * pybind11/tools/pybind11Tools.cmake:149 (target_link_libraries)
   * pybind11/tools/pybind11Tools.cmake:176 (target_link_libraries)

This warning is for project developers.  Use -Wno-dev to suppress it.

改为

target_link_libraries(robot_interface PRIVATE ${EXTRA_LIBS})
 类似资料:

相关阅读

相关文章

相关问答