很多人一開始使用Sophus庫時會碰到下面的錯誤:
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "FindSophus.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Sophus", but
CMake did not find one.
Could not find a package configuration file provided by "Sophus" with any
of the following names:
SophusConfig.cmake
sophus-config.cmake
Add the installation prefix of "Sophus" to CMAKE_PREFIX_PATH or set
"Sophus_DIR" to a directory containing one of the above files. If "Sophus"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
這時,CMakeLists.txt檔案中查找Sophus庫的語句多半是這麼寫的:
find_package(Sophus REQUIRED)
提供一種解決方案,觀看錯誤資訊,其實就是找不到Sophus庫和頭檔案的内容:
set(Sophus_INCLUDE_DIRS "放置你的Sophus頭檔案檔案夾路徑")
set(Sophus_LIBS "放置你的Sophus庫檔案的檔案夾路徑,指明相應的庫檔案")
比如,我的是這樣的:
set(Sophus_INCLUDE_DIRS "/usr/local/include/sophus")
set(Sophus_LIBS "/usr/local/lib/libSophus.so")
include_directories(
${Sophus_INCLUDE_DIRS}
)
然後再将你的執行檔案連結上Sophus庫檔案
這樣的話,上述編譯錯誤應該就可以消失了。