在 Debian 上,我已经安装了 cmake 和 geolib,如下所示:
stew@stewbian:~$apt-get install build-essential cmake libgeographic-dev
我的 CMakeLists.txt 文件如下所示:
cmake_minimum_required(VERSION 3.7)
project(geoexample)
find_package(GeographicLib REQUIRED)
add_executable(geoexample main.cpp)
target_include_directories(geoexample PRIVATE ${GeographicLib_INCLUDE_DIRS})
target_compile_definitions(geoexample PRIVATE ${GeographicLib_DEFINITIONS})
target_link_libraries (geoexample ${GeographicLib_LIBRARIES})
我的 main.cpp 也很简单(直接取自示例):
#include <iostream>
#include <GeographicLib/Geodesic.hpp>
using namespace std;
using namespace GeographicLib;
int main() {
const Geodesic& geod = Geodesic::WGS84();
// Distance from JFK to LHR
double
lat1 = 40.6, lon1 = -73.8, // JFK Airport
lat2 = 51.6, lon2 = -0.5; // LHR Airport
double s12;
geod.Inverse(lat1, lon1, lat2, lon2, s12);
cout << s12 / 1000 << " km\n";
return 0;
}
当我跑步时,mkdir build && cd build && cmake ..
我得到
stew@stewbian:~/src/geoexample/build$ cmake ..
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindGeographicLib.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"GeographicLib", but CMake did not find one.
我认为默认情况下, cmake 搜索/usr/share/cmake-3.7/Modules
,但 libgeographic-dev 似乎已将其 Find*.cmake 安装到/usr/share/cmake/geographiclib/FindGeographicLib.cmake
. 这令人沮丧,但我自己(以及需要编译我的代码的每个人)应该能够为这个简单的案例使用一种解决方法(如果我还需要包含类似 FindBoost.cmake 的东西,它就不会那么好用旧位置)。
stew@stewbian:~/src/geoexample/build$ cmake .. -DCMAKE_MODULE_PATH=/usr/share/cmake/geographiclib
CMake Error at /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find GeographicLib (missing: GeographicLib_LIBRARY_DIRS
GeographicLib_INCLUDE_DIRS)
Call Stack (most recent call first):
/usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake/geographiclib/FindGeographicLib.cmake:28 (find_package_handle_standard_args)
CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
现在我不确定在这里做什么。我可以确认已安装 libgeographic-dev 软件包/usr/lib/x86_64-linux-gnu/libGeographic.a
并且/usr/lib/x86_64-linux-gnu/libGeographic.so