导入 C++在 mac 上使用 vcpkg 安装库吗?
我的目标是在我的 Mac 上安装一个库 (rbdl-orb) 并导入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 example”会产生以下错误:
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++ 编译器知道在哪里安装当看到命令“导入”时查找文件。 该库的 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 example”会产生以下错误:
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++ 程序中?
My goal is to install a library (rbdl-orb) on my Mac and import the library in a C++ program.
My first attempt was to clone the library and run the included example directly. The program "example.cc" starts with the following two lines:
#include <iostream>
#include <rbdl/rbdl.h>
The CMake file follows:
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}
)
Typing "make example" yields the following error:
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
I am guessing that there are steps needed to install the library, such that the C++ compiler knows where to look for the files when it sees the command "import". The library's GitHub notes that the package is available for installation through vcpkg.
I installed vcpkg by following the instructions. Then, I built the library by typing "vcpkg install rbdl" in a Terminal. Typing "vcpkg list" in the working directory shows that the library appears to be installed:
(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
Unfortunately, typing "make example" again yields the following error:
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
The error suggests that the C++ compiler is not aware of the location where the library was installed.
How can I correctly install the library and import it in my C++ program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是最好的继续方式,我假设 mac 和 linux 在这里是相似的...
我想你可以搜索 rgbd.cmake 的位置并附加它到
CMAKE_MODULE_PATH
变量。为了进行非常快速的搜索,我以这种方式使用了 ripgrep :如果你有输出,请告诉我。如果是这样,请将其添加到 cmakelist:
list(APPEND CMAKE_MODULE_PATH "the path to rgbd.cmake")
希望有所帮助。
I've no certitude this is the best way to proceed, and I'm assuming mac and linux are similar here...
I guess you could search for the location of the rgbd.cmake and append it to the
CMAKE_MODULE_PATH
variable. to have a very fast search I'd used ripgrep that way :let me know if you have an outpput at all. If so, then add it to the cmakelist:
list(APPEND CMAKE_MODULE_PATH "the path to rgbd.cmake")
hope that helps.
使用“ sudo”重新安装了库,并开始使用vcpkg安装,然后对CMAKE文件进行以下更改:
SET(CMAKE_CXX_STANDARD 11)
之后,在这些更改之后,库正确运行。
Reinstalled the library using "sudo" and started using the vcpkg installation and made the following change to the CMake file:
SET(CMAKE_CXX_STANDARD 11)
After these changes, the library is running correctly.