正常情况拿到一个新的cpp库,可以用以下三连操作完成安装
mkdir build
cd build
cmake ../
make
sudo make install
我需要安装A库,并在B库make中导入A库,但今天我没有sudo权限,因此最后一步无法执行。
your_path
下make install DESTDIR=/your_path
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})
cmake, makefile.txt, make关系简介 : 对于make与cmake的关系简单理解
cmake 简单示例 : 很好很简洁的一个cmake样例
CMakeLists.txt
文件中输出变量值用以debugMESSAGE (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})