HuaYuXiao / sdf_tools

Builds 2D signed distance fields from images, 3D signed distance fields from pointclouds, 3D signed distance fields from Octomap, provides a lightweight signed distance field library, message types for signed distance fields, and tools to compress signed distance fields for transport.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined reference to `ZlibHelpers::CompressBytes(std::vector<unsigned char, std::allocator<unsigned char> > const&)'

HuaYuXiao opened this issue · comments

/usr/bin/ld: /home/hyx020222/planner_ws/devel/lib/libsdf_tools.so: undefined reference to ZlibHelpers::CompressBytes(std::vector<unsigned char, std::allocator<unsigned char> > const&)' /usr/bin/ld: /home/hyx020222/planner_ws/devel/lib/libsdf_tools.so: undefined reference to ZlibHelpers::DecompressBytes(std::vector<unsigned char, std::allocator > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [plan_manage/CMakeFiles/traj_server.dir/build.make:372: /home/hyx020222/planner_ws/devel/lib/prometheus_plan_manage/traj_server] Error 1
make[1]: *** [CMakeFiles/Makefile2:4262: plan_manage/CMakeFiles/traj_server.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: /home/hyx020222/planner_ws/devel/lib/libsdf_tools.so: undefined reference to ZlibHelpers::CompressBytes(std::vector<unsigned char, std::allocator<unsigned char> > const&)' /usr/bin/ld: /home/hyx020222/planner_ws/devel/lib/libsdf_tools.so: undefined reference to ZlibHelpers::DecompressBytes(std::vector<unsigned char, std::allocator > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [plan_manage/CMakeFiles/dyn_planner_node.dir/build.make:417: /home/hyx020222/planner_ws/devel/lib/prometheus_plan_manage/dyn_planner_node] Error 1
make[1]: *** [CMakeFiles/Makefile2:3547: plan_manage/CMakeFiles/dyn_planner_node.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Invoking "make install -j22 -l22" failed

这个错误表明链接器在链接过程中找不到名为ZlibHelpers::CompressBytesZlibHelpers::DecompressBytes的函数的定义,它们被用于库libsdf_tools.so中的某些部分。

这通常是由于以下原因之一导致的:

  1. 缺少对应的库文件: 确保你的项目正确链接了包含ZlibHelpers::CompressBytesZlibHelpers::DecompressBytes函数定义的库文件。可能需要将相关的库文件添加到链接命令中,以确保链接器可以找到这些函数的定义。

  2. 链接顺序问题: 如果libsdf_tools.so依赖于另一个包含ZlibHelpers定义的库文件,确保它在libsdf_tools.so之前被链接。

  3. 编译器和链接器的路径设置不正确: 确保编译器和链接器可以找到ZlibHelpers库文件。你可以在CMakeLists.txt中使用target_link_libraries命令来指定链接的库文件。

  4. 项目的依赖关系不正确: 如果ZlibHelpers函数是从其他库中引入的,确保你的项目正确地声明了对这些库的依赖关系。

请检查这些方面,以找出导致链接错误的原因,并进行相应的修正。

这段错误信息是在使用CMake构建系统进行编译时遇到的链接错误。错误的核心是链接器(ld)无法找到ZlibHelpers::CompressBytesZlibHelpers::DecompressBytes这两个函数的定义。这通常意味着以下几个问题之一:

  1. 未链接Zlib库:如果你的程序依赖于Zlib库进行压缩和解压缩操作,你需要确保在CMakeLists.txt文件中使用了find_package(ZLIB)来找到Zlib库,并且在链接时使用了target_link_libraries来链接Zlib库。

  2. Zlib库版本不兼容:如果你链接的Zlib库版本与你的代码所依赖的版本不兼容,可能会导致链接错误。

  3. 头文件路径不正确:如果Zlib库的头文件没有被正确地包含在编译器的搜索路径中,也会导致链接错误。你需要检查CMakeLists.txt文件中是否使用了include_directories来包含Zlib头文件的路径。

  4. 编译Zlib库时出现问题:如果Zlib库本身在编译时有问题,或者没有正确安装,也可能导致链接错误。

  5. CMakeLists.txt配置错误:可能是CMakeLists.txt文件中的配置有误,导致链接器无法找到相应的定义。

为了解决这个问题,你可以尝试以下步骤:

  • 确保Zlib库已经安装在你的系统上,并且CMake能够找到它。
  • 检查CMakeLists.txt文件,确保你已经正确地添加了Zlib库的链接指令。
  • 如果你有自己的Zlib实现,确保ZlibHelpers::CompressBytesZlibHelpers::DecompressBytes的实现存在于你的项目中,并且没有被意外地排除在编译之外。
  • 清理(clean)你的构建目录,然后重新运行CMake和make命令。

如果你不熟悉CMake或链接过程,可能需要查看一些CMake和Zlib的文档,或者寻求有经验的开发者的帮助。