我的目标是在我的Mac上安装一个库(rbdl-球),并在一个C++程序中导入这个库。
我的第一次尝试是克隆库并直接运行包含的示例。程序"example.cc“从以下两行开始:
#include <iostream>
#include <rbdl/rbdl.h>CMake文件如下:
PROJECT (RBDLEXAMPLE CXX)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
# We need to add the project source path to the CMake module path so that
# the FindRBDL.cmake script can be found.
LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} )
SET(CUSTOM_RBDL_PATH "" CACHE PATH "Path to specific RBDL Installation")
# Search for the RBDL include directory and library
FIND_PACKAGE (RBDL REQUIRED)
FIND_PACKAGE (Eigen3 3.0.0 REQUIRED)
# Add the include directory to the include paths
INCLUDE_DIRECTORIES ( ${RBDL_INCLUDE_DIR} ${EIGEN3_INCLUDE_DIR} )
# Create an executable
ADD_EXECUTABLE (example example.cc)
# And link the library against the executable
TARGET_LINK_LIBRARIES (example
${RBDL_LIBRARY}
)键入“make样例”将产生以下错误:
c++ example.cc -o example
example.cc:10:10: fatal error: 'rbdl/rbdl.h' file not found
#include <rbdl/rbdl.h>
^~~~~~~~~~~~~
1 error generated.
make: *** [example] Error 1我猜想,安装库需要采取一些步骤,以便C++编译器在看到命令"import“时知道在哪里查找文件。图书馆的GitHub注意到这个包可以通过vcpkg安装。
我按照使用说明安装了vcpkg。然后,我通过在终端中输入"vcpkg install rbdl“构建了这个库。在工作目录中键入"vcpkg list“显示,该库似乎已安装:
(base) my_name@my_name-MacBook-Pro current_directory % vcpkg list
eigen3:arm64-osx 3.4.0#2 C++ template library for linear algebra: matrice...
rbdl:arm64-osx 2.6.0#2 Rigid Body Dynamics Library
vcpkg-cmake-config:arm64-osx 2022-02-06
vcpkg-cmake:arm64-osx 2022-04-07不幸的是,键入“make样例”再次导致以下错误:
c++ example.cc -o example
example.cc:10:10: fatal error: 'rbdl/rbdl.h' file not found
#include <rbdl/rbdl.h>
^~~~~~~~~~~~~
1 error generated.
make: *** [example] Error 1该错误表明,C++编译器不知道安装库的位置。
如何正确安装库并将其导入C++程序?
发布于 2022-04-20 13:03:48
使用"sudo“重新安装库,并开始使用vcpkg安装,并对CMake文件进行以下更改:
集合(CMAKE_CXX_STANDARD 11)
这些更改之后,库将正确运行。
发布于 2022-04-12 17:24:03
我不确定这是最好的方法,我假设mac和linux在这里是相似的.
我想您可以搜索rgbd.cmake的位置并将其附加到CMAKE_MODULE_PATH变量中。为了进行非常快速的搜索,我采用了这种方式:
$ rg --files / 2>/dev/null|rg rgbd.*\\.cmake$
... expect to chose a path from the outputed ones.如果你有输出,请告诉我。如果是,那么将其添加到cmakelist中:
list(APPEND CMAKE_MODULE_PATH "the path to rgbd.cmake")
希望这能帮上忙。
https://stackoverflow.com/questions/71846557
复制相似问题