GeographicLib  1.46
Getting started
Back to Installing GeographicLib. Forward to Utility programs. Up to Contents.

Much (but not all!) of the useful functionality of GeographicLib is available via simple command line utilities. Interfaces to some of them are available via the web. See Utility programs for documentation on these.

In order to use GeographicLib from C++ code, you will need to

Here is a very simple test code, which uses the Geodesic class:

// Small example of using the GeographicLib::Geodesic class
#include <iostream>
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;
}

This example is examples/example-Geodesic-small.cpp. If you compile, link, and run it according to the instructions above, it should print out

  5551.76 km 

Here is a complete CMakeList.txt files you can use to build this test code using the installed library:

project (geodesictest)
cmake_minimum_required (VERSION 2.8.4)

find_package (GeographicLib 1.34 REQUIRED)

if (NOT MSVC)
  set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif ()

if (CMAKE_VERSION VERSION_LESS 2.8.11)
  include_directories (${GeographicLib_INCLUDE_DIRS})
  add_definitions (${GeographicLib_DEFINITIONS})
endif ()
add_executable (${PROJECT_NAME} example-Geodesic-small.cpp)
target_link_libraries (${PROJECT_NAME} ${GeographicLib_LIBRARIES})

if (MSVC)
  get_target_property (_LIBTYPE ${GeographicLib_LIBRARIES} TYPE)
  if (_LIBTYPE STREQUAL "SHARED_LIBRARY")
    # On Windows systems, copy the shared library to build directory
    add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E
      copy $<TARGET_FILE:${GeographicLib_LIBRARIES}> ${CMAKE_CFG_INTDIR}
      COMMENT "Copying shared library for GeographicLib")
  endif ()
endif () 

The next steps are:

Here's a list of some of the abbreviations used here with links to the corresponding Wikipedia articles:

Back to Installing GeographicLib. Forward to Utility programs. Up to Contents.