CXX0017: 错误: 没有找到符号

本文档详细介绍了如何解决在Debug配置状态下遇到的CXX0017错误,即编译过程中找不到特定符号的问题。通过分析和调试,提供了解决此问题的初始解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编程环境:Visual Studio 2010

首先确定是在 Debug 配置状态。

初始解决方案如下:

错误现象:CXX0017: Error: symbol this not found

                
../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::parent_path() const' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::directory_iterator::operator*() const' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::has_parent_path() const' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::_M_find_extension() const' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::symlink_status(std::filesystem::__cxx11::path const&)' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::has_root_directory() const' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::directory_iterator::operator++()' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path const&, std::filesystem::directory_options, std::error_code*)' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::read_symlink(std::filesystem::__cxx11::path const&)' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::replace_extension(std::filesystem::__cxx11::path const&)' ../../../lib/libg2o_stuff.so.0.2.0: undefined reference to `std::filesystem::__cxx11::path::has_filename() const' collect2: error: ld returned 1 exit status g2o/apps/g2o_cli/CMakeFiles/g2o_cli_application.dir/build.make:99: recipe for target 'bin/g2o' failed make[2]: *** [bin/g2o] Error 1 CMakeFiles/Makefile2:1230: recipe for target 'g2o/apps/g2o_cli/CMakeFiles/g2o_cli_application.dir/all' failed make[1]: *** [g2o/apps/g2o_cli/CMakeFiles/g2o_cli_application.dir/all] Error 2 Makefile:155: recipe for target 'all' failed make: *** [all] Error 2
最新发布
08-07
<think>我们正在解决链接错误:undefined reference to `GeographicLib::Geoid::Geoid`。这个错误通常发生在编译过程中,链接器无法找到GeographicLib库中Geoid类的构造函数(或其他成员)的实现。在ROS中使用mavros时,mavros依赖于GeographicLib库,因此需要确保该库正确安装并且被链接。 可能的原因和解决方案如下: 1. **未安装GeographicLib库**:确保系统中已经安装了GeographicLib库。 在Ubuntu上,可以使用以下命令安装: ```bash sudo apt-get install libgeographic-dev ``` 2. **CMakeLists.txt配置问题**:在ROS包的CMakeLists.txt中,需要正确链接GeographicLib库。 在`find_package`中确保包含GeographicLib,并在`target_link_libraries`中添加`GeographicLib::GeographicLib`。 例如: ```cmake find_package(GeographicLib REQUIRED) # ... target_link_libraries(your_target ${catkin_LIBRARIES} GeographicLib::GeographicLib ) ``` 3. **安装的GeographicLib版本与mavros要求的版本不匹配**:检查mavros所需的GeographicLib版本,并确保安装的版本符合要求。可以通过更新mavros或GeographicLib来解决。 4. **环境变量问题**:确保库的路径在链接器的搜索路径中。如果手动安装了GeographicLib,可能需要设置`LD_LIBRARY_PATH`或使用`ldconfig`。 5. **ROS工作空间依赖问题**:在ROS工作空间中,确保已经重新构建了所有依赖项。可以尝试以下命令: ```bash catkin clean # 慎用,这会清除整个build和devel目录 catkin build ``` 6. **检查mavros的安装**:确保mavros已经正确安装,并且支持GeographicLib。可以尝试重新安装mavros: ```bash sudo apt-get install ros-<your_ros_distro>-mavros ros-<your_ros_distro>-mavros-extras ``` 7. **手动安装GeographicLib**:如果通过apt安装的版本不满足要求,可以尝试从源码安装GeographicLib。注意要安装到系统路径或者设置好环境变量。 8. **多个版本的GeographicLib冲突**:如果系统中有多个版本的GeographicLib,可能会导致链接错误。需要确保链接器找到的是正确的版本。 9. **检查头文件与库文件是否匹配**:有时候头文件和库文件版本不一致也会导致链接错误。确保编译时使用的头文件与链接的库文件来自同一版本。 10. **使用pkg-config**:如果GeographicLib提供了pkg-config文件,可以在CMakeLists.txt中使用`pkg_check_modules`来查找。 根据上述步骤,通常可以解决链接错误。 由于我们是在ROS环境下,特别要注意第2点(CMakeLists.txt的配置)和第5点(重新构建整个工作空间)。 下面是一个修改CMakeLists.txt的示例: 假设你的ROS包名为`my_package`,可执行文件名为`my_node`,那么CMakeLists.txt中应该有类似下面的内容: ```cmake cmake_minimum_required(VERSION 3.0.2) project(my_package) # 添加catkin和其他依赖 find_package(catkin REQUIRED COMPONENTS roscpp # ... 其他依赖 ) # 添加GeographicLib find_package(GeographicLib REQUIRED) # 声明catkin包 catkin_package( # INCLUDE_DIRS include # LIBRARIES my_package # CATKIN_DEPENDS roscpp ... # DEPENDS GeographicLib ) include_directories( ${catkin_INCLUDE_DIRS} ) # 添加可执行文件 add_executable(my_node src/my_node.cpp) # 链接库 target_link_libraries(my_node ${catkin_LIBRARIES} GeographicLib::GeographicLib ) ``` 注意:在较新版本的GeographicLib中,通常使用`GeographicLib::GeographicLib`作为目标名称。如果使用旧版本,可能需要使用`${GeographicLib_LIBRARIES}`。 如果问题仍然存在,请提供更多关于你的环境(如ROS发行版、Ubuntu版本)和错误完整信息。 下面生成相关问题:</think>### 解决链接错误:`undefined reference to GeographicLib::Geoid::Geoid` 在 ROS 中使用 mavros 时遇到 `undefined reference to GeographicLib::Geoid::Geoid` 错误,通常是由于 **GeographicLib 库未正确链接**导致的。以下是系统化的解决步骤: --- #### 1. **安装 GeographicLib 库** ```bash sudo apt-get install libgeographic-dev # 安装核心库 sudo apt-get install geographiclib-tools # 可选:安装工具集 ``` 验证安装: ```bash dpkg -l | grep libgeographic # 应显示类似 "libgeographic-dev 1.50.1-1" ``` --- #### 2. **更新 mavros 依赖** 确保 mavros 及其依赖已完整安装: ```bash sudo apt-get install ros-${ROS_DISTRO}-mavros \ ros-${ROS_DISTRO}-mavros-extras \ ros-${ROS_DISTRO}-libgeographic-dev ``` 替换 `${ROS_DISTRO}` 为你的 ROS 版本(如 `noetic`)。 --- #### 3. **修改 CMakeLists.txt** 在 ROS 包的 `CMakeLists.txt` 中添加 GeographicLib 的链接: ```cmake find_package(GeographicLib REQUIRED) # 在 find_package(catkin ...) 后添加 include_directories( ${GeographicLib_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} ) target_link_libraries(your_node ${catkin_LIBRARIES} ${GeographicLib_LIBRARIES} # 添加此行 ) ``` --- #### 4. **检查库路径** 确保链接器能找到库文件: ```bash # 检查库文件是否存在 ls /usr/lib/x86_64-linux-gnu/libGeographic.so # 默认路径 # 若手动安装,添加自定义路径到 LD_LIBRARY_PATH export LD_LIBRARY_PATH=/custom/path:$LD_LIBRARY_PATH ``` --- #### 5. **重新编译工作空间** 清理并重新编译: ```bash cd ~/catkin_ws catkin clean -y # 彻底清理 catkin build # 重新构建 source devel/setup.bash ``` --- #### 6. **验证链接符号** 检查库中是否包含 `Geoid::Geoid` 符号: ```bash nm -D /usr/lib/x86_64-linux-gnu/libGeographic.so | grep "Geoid::Geoid" ``` 正常应输出类似:`00000000000d7e70 T _ZN12GeographicLib5GeoidC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_bbd` --- #### 常见问题原因 - **库版本冲突**:系统中存在多个 GeographicLib 版本(如手动编译与 apt 安装混合)。 - **头文件/库不匹配**:编译时使用了旧版头文件,但链接了新版库(或反之)。 - **ROS 环境未更新**:安装库后未重新运行 `rosdep update`。 --- ### 相关问题 1. 如何检查 ROS 包中缺失的链接库依赖? 2. 在 CMake 中如何正确处理多个第三方库的链接顺序? 3. ROS 的 `catkin build` 和 `catkin_make` 在依赖管理上有哪些区别? [^1]: GeographicLib 官方文档:https://geographiclib.sourceforge.io [^2]: ROS mavros 安装指南:http://wiki.ros.org/mavros#Installation
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值