因此,在 this 和 this 的帮助下,我能够构建我的本地项目。到目前为止,一切都很好。如何在我的 C++ 项目中链接本地安装的 SDK 静态库?
基本上,SDK 会在其本地目录中生成库,在其
Makefile
中,它没有install
规则。我的意思是,我可以运行make
,但在那之后,如果我运行sudo make install
,那么它会出现make: *** No rule to make target 'install'. Stop.
错误。
然而,主要问题在于我必须在我的repo的
CMakeLists.txt
中硬编码RPLidar SDK路径。现在,每当我的团队中有其他人开始在该repo上工作时(这是相当明显的),他/她首先必须更新CMakeLists.txt
。这不是一个好的想法/实践!为了解决这个问题,我更新了RPLidar SDK的Makefile
如下:.
.
.
RPLIDAR_RELEASE_LIB := $(HOME_TREE)/output/Linux/Release/librplidar_sdk.a
install: $(RPLIDAR_RELEASE_LIB)
install -d $(DESTDIR)/usr/local/lib/rplidar/Release/
install -m 644 $(RPLIDAR_RELEASE_LIB) $(DESTDIR)/usr/local/lib/rplidar/Release/
RPLIDAR_DEBUG_LIB := $(HOME_TREE)/output/Linux/Debug/librplidar_sdk.a
install: $(RPLIDAR_DEBUG_LIB)
install -d $(DESTDIR)/usr/local/lib/rplidar/Debug/
install -m 644 $(RPLIDAR_DEBUG_LIB) $(DESTDIR)/usr/local/lib/rplidar/Debug/
RPLIDAR_HEADERS := $(HOME_TREE)/sdk/include
install: $(RPLIDAR_HEADERS)
install -d $(DESTDIR)/usr/local/include/rplidar/
cp -r $(RPLIDAR_HEADERS)/* $(DESTDIR)/usr/local/include/rplidar/
RPLIDAR_HEADERS_HAL := $(HOME_TREE)/sdk/src/hal
install: $(RPLIDAR_HEADERS_HAL)
install -d $(DESTDIR)/usr/local/include/rplidar/
cp -r $(RPLIDAR_HEADERS_HAL) $(DESTDIR)/usr/local/include/rplidar/
由于此更新,现在我可以运行
sudo make install
,它基本上将RPLidar SDK的头文件从本地目录复制到/usr/local/rplidar/
目录。 它还将lib文件复制到/usr/local/lib/rplidar/<Debug>或<Release>/
目录。现在,在我的本地项目中,我将CMakeLists.txt
更新如下:cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(<project_name>)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
SET(CMAKE_CXX_FLAGS -pthread)
include_directories(include)
add_executable(${PROJECT_NAME} src/main.cpp src/another_src_file.cpp)
find_package(rplidar REQUIRED)
include_directories(${rplidar_INCLUDE_DIRS})
link_directories(${rplidar_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${rplidar_LIBRARY})
然而,在运行
cmake ..
命令时,我遇到了这个错误:.
.
.
CMake Error at CMakeLists.txt:12 (find_package):
By not providing "Findrplidar.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "rplidar", but
CMake did not find one.
Could not find a package configuration file provided by "rplidar" with any
of the following names:
rplidarConfig.cmake
rplidar-config.cmake
Add the installation prefix of "rplidar" to CMAKE_PREFIX_PATH or set
"rplidar_DIR" to a directory containing one of the above files. If
"rplidar" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
据我所知,RPLidar SDK没有
rplidarConfig.cmake
或rplidar-config.cmake
文件。如何解决这个错误?