Undefined reference to `GeographicLib::UTMUPS::Forward(...)
I am running ROS melodic on Ubuntu 18.04. I installed robot_localization via: sudo apt-get install ros-melodic-robot-localization
I am trying to use the RobotLocalization::NavsatConversions::LLtoUTM function from the robot_localization function but I am getting the following error:
CMakeFiles/gps_waypoint_mapping.dir/src/gps_waypoint_mapping.cpp.o: In function RobotLocalization::NavsatConversions::LLtoUTM(double, double, double&, double&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, double&)':
gps_waypoint_mapping.cpp:(.text+0x64): undefined reference to GeographicLib::UTMUPS::Forward(double, double, int&, bool&, double&, double&, double&, double&, int, bool)'
gps_waypoint_mapping.cpp:(.text+0xa1): undefined reference to `GeographicLib::MGRS::Forward(int, bool, double, double, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
The snippet of code from gps_waypoint_mapping.cpp that uses LLtoUTM is:
geometry_msgs::PointStamped latLongtoUTM(double lati_input, double longi_input)
{
double utm_x = 0, utm_y = 0;
geometry_msgs::PointStamped UTM_point_output;
//convert lat/long to utm
RobotLocalization::NavsatConversions::LLtoUTM(lati_input, longi_input, utm_y, utm_x, utm_zone);
//Construct UTM_point and map_point geometry messages
UTM_point_output.header.frame_id = "utm";
UTM_point_output.header.stamp = ros::Time(0);
UTM_point_output.point.x = utm_x;
UTM_point_output.point.y = utm_y;
UTM_point_output.point.z = 0;
return UTM_point_output;
}
I am pretty sure that GeographicLib is one of the dependencies of robot_localization so it was installed alongside. I ran rosdep install --from-paths src --ignore-src -r -y aswell
to make sure.
Here is my CMakeLists.txt, sorry I am new to ROS so I didnt really know what to include and what not to include:
cmake_minimum_required(VERSION 3.0.3)
project(outdoor_waypoint_nav)
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
tf
roslib
roslaunch
)
catkin_package()
roslaunch_add_file_check(launch)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(gps_waypoint src/gps_waypoint.cpp)
#add_executable(gps_waypoint_continuous src/gps_waypoint_continuous.cpp)
add_executable(gps_waypoint_continuous1 src/gps_waypoint_continuous1.cpp)
add_executable(gps_waypoint_continuous2 src/gps_waypoint_continuous2.cpp)
add_executable(gps_waypoint_mapping src/gps_waypoint_mapping.cpp)
add_executable(collect_gps_waypoints src/collect_gps_waypoints.cpp)
add_executable(plot_gps_waypoints src/plot_gps_waypoints.cpp)
add_executable(calibrate_heading src/calibrate_heading.cpp)
add_executable(safety_node src/safety_node.cpp)
add_executable(switch_controllers src/switch_controllers.cpp)
target_link_libraries(gps_waypoint ${catkin_LIBRARIES})
# target_link_libraries(gps_waypoint_continuous ${catkin_LIBRARIES})
target_link_libraries(gps_waypoint_continuous1 ${catkin_LIBRARIES})
target_link_libraries(gps_waypoint_continuous2 ${catkin_LIBRARIES})
target_link_libraries(gps_waypoint_mapping ${catkin_LIBRARIES})
target_link_libraries(collect_gps_waypoints ${catkin_LIBRARIES})
target_link_libraries(plot_gps_waypoints ${catkin_LIBRARIES})
target_link_libraries(calibrate_heading ${catkin_LIBRARIES})
target_link_libraries(safety_node ${catkin_LIBRARIES})
target_link_libraries(switch_controllers ${catkin_LIBRARIES})
install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
Would be good to also include the snippet of your
CMakeLists.txt
that builds the chunk of code shown in the original post. This is likely a linking error caused by missing something in theCMakeLists.txt
You are using a function from robot_localiztion but you haven’t link against it in your CmakeLists.txt. Add robot_localization package to find_packages() function
Thanks for the reply! I just added robot_localization to my find_packages() but the same problem persists.
try download the old version of navsat_conversions.h from github and modify the include header in your gps cpp file to point to this .h file.
Hey, did it worked? I am facing this problem too . CMakeFiles/plot_gps_waypoints.dir/src/plot_gps_waypoints.cpp.o: In function
RobotLocalization::NavsatConversions::LLtoUTM(double, double, double&, double&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, double&)': plot_gps_waypoints.cpp:(.text+0x64): undefined reference to
GeographicLib::UTMUPS::Forward(double, double, int&, bool&, double&, double&, double&, double&, int, bool)' plot_gps_waypoints.cpp:(.text+0xa1): undefined reference to `GeographicLib::MGRS::Forward(int, bool, double, double, int, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> >&)' collect2: error: ld returned 1 exit status waypoint_nav/outdoor_waypoint_nav/CMakeFiles/plot_gps_waypoints.dir/build.make:122: recipe for target '/home/root1/workspace_test/devel/lib/outdoor_waypoint_nav/plot_gps_waypoints' failed make[2]: * [/home/root1/workspace_test/devel/lib/outdoor_waypoint_nav/plot_gps_waypoints] Er