pcl icon indicating copy to clipboard operation
pcl copied to clipboard

[compile error] Linker error: libpcl_io_ply.a is not added to ${PCL_LIBRARIES}, nor is it linked to libpcl_io.

Open tsijs opened this issue 5 years ago • 11 comments

When compiling pcl with vcpkg, and using #include <pcl/io/ply_io.h>, there occures a linker error which happens because libpcl_io_ply.a is not added to ${PCL_LIBRARIES}, nor is it linked to libpcl_io.a

Please paste the compilation results/errors.

To Reproduce

  • Build pcl with the latest vcpkg port.
  • Add pcl to a personal target in cmake by following the instructions here: https://pointclouds.org/documentation/tutorials/using_pcl_pcl_config.html
  • Run:
mkdir build && cd build
cmake ..  
make foobar VERBOSE=1 2>&1 | grep pcl_io

Output: lib_pcl_io_ply is not printed in the output. "<vcpkg_dirdir>/installed/x64-linux/lib/libpcl_io.a(ply_io.cpp.o): In function `pcl::PLYReader::parse(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'" complains about not being able to link to lib_pcl_io_ply.

Remember to reproduce the error in a clean rebuild (removing all build objects and starting build from scratch)

Your Environment (please complete the following information):

  • OS: Ubuntu 18.04 docker
  • Compiler: gcc 9
  • PCL Version 1.11.0
  • PCL Type: Compiled with vcpkg

If PCL was compiled from source or failure in compiling PCL itself:

  • GPU, Kinfu, CUDA enabled? No
  • List and Version of dependencies used - deemed irrelevant
  • Compilation flags are used -O3 -fPIC, nothing else special.

If compiling against PCL:

  • Checked CMakeLists.txt for simple errors like missing find_package or target_link_libraries? - yes

Possible Solution

It seems that pcl_io is not linked to pcl_io_ply when building pcl statically, hence it needs pcl_io_ply when linked to, but there is no nice way to obtain the location of pcl_io_ply, because it is not available in the libraries cmake variable.

So my naive proposal would be: either make pcl_io with pcl_io_ply or add it to the libraries variable.

tsijs avatar Sep 24 '20 11:09 tsijs

Same problem here.

@tsijs , do you have a solution now?

wyhao31 avatar Dec 02 '20 19:12 wyhao31

https://github.com/PointCloudLibrary/pcl/blob/pcl-1.11.1/io/CMakeLists.txt#L3

io subsystem only declares dependency on "common" and "octree" subsystems, so only those dependencies appear in PCLConfig.cmake. The easiest way to fix this would be to merge pcl_io_ply into pcl_io target. Another option might be to make pcl_io_ply as subsubsystem of pcl_io subsystem.

I think there are additional problems with static libraries. Dependencies on third-party libraries like boost, vtk, etc also need to be specified for in EXT_DEPS, which seems to be missing here: https://github.com/PointCloudLibrary/pcl/blob/pcl-1.11.1/io/CMakeLists.txt#L10

I am not sure why pcl project decided to implement custom script to generate PCLConfig.cmake instead of just using cmake install(EXPORT): https://cmake.org/cmake/help/latest/command/install.html#export

alokpr avatar Dec 02 '20 23:12 alokpr

Maybe a little too late to the party, but I worked around the problem by adding the io lib manually in my own cmakelist.

It doesn't deserve an elegance medal, but it works:

set(PCL_PLY_IO_LIBRARY_PATH "${VCPKG_ROOT_DIR}/installed/x64-linux/lib/libpcl_io_ply.a")

target_link_libraries(${PROJECT_NAME} PRIVATE ${PCL_PLY_IO_LIBRARY_PATH} }

tsijs avatar Dec 18 '20 08:12 tsijs

I just ran into the same problem and can be reproduced with the minimal example below:

./vcpkg install pcl

CMakeLists.txt

set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)

cmake_minimum_required(VERSION 3.20)

project(example)

find_package(PCL)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/main.cpp)

target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES})

main.cpp

#include "pcl/io/ply_io.h"
#include "pcl/point_types.h"

int main() {
  std::string ply_file;
  pcl::PointCloud<pcl::PointXYZ> cld;

  pcl::PLYReader Reader;

  Reader.read(ply_file, cld);

  return 0;
}

mkdir build && cd build && cmake .. && make shows the below error:

[ 50%] Building CXX object CMakeFiles/example.dir/main.cpp.o
[100%] Linking CXX executable example
/usr/bin/ld: /home/jasjuang/vcpkg/installed/x64-linux/lib/libpcl_io.a(ply_io.cpp.o): in function `pcl::PLYReader::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
ply_io.cpp:(.text+0x2ca3): undefined reference to `pcl::io::ply::ply_parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example.dir/build.make:130: example] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/example.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

jasjuang avatar Sep 18 '21 05:09 jasjuang

This issue can NOT easily fixed.

pcl_io_ply is a submodule of pcl_io, and the build statement is placed in io/CMakeLists.txt.

However, pcl declares dependencies through internal SUBSYS_DEPS, and all subsystems use the related folder names, which means that pcl_io_ply cannot be used as one of the subsystems, and is added as a dependency of pcl_io using the internal dependency processing mode of pcl.

Moreover, pcl does not use the cmake export function, but uses SUBSYS_DEPS to configure PCLConfig.cmake.in to generate PCLConfig.cmake, which means that we cannot fix this problem through target_link_libraries.

JackBoosY avatar Nov 10 '21 08:11 JackBoosY

the undefined symbol error for pcl::io::ply::ply_parser::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) suddenly showed up for me with 1.11 with a static build also, despite having successfully used it for shared libraries. Any workarounds?

themightyoarfish avatar Jan 13 '22 12:01 themightyoarfish

same error for me, any progress?

liuzhy71 avatar Mar 13 '22 17:03 liuzhy71

You can add in your CmakeLists something like: target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES}) // original from @jasjuang example target_link_libraries(${PROJECT_NAME} pcl_io_ply) // added line that solves the linking error (given the path where the libraries is located is added) Then it builds fine.

larshg avatar Mar 15 '22 13:03 larshg

undefined symbol error for pcl::io::ply::ply_parser::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)

Still an issue. (Trying to fix the rtabmap vcpkg port for x64-linux static linkage.) pcl_io_ply is a lib with usage requirements, but without pkg-config file and not handled by CMake config/modules.

dg0yt avatar Mar 25 '24 09:03 dg0yt

Tentative patch which keeps the separate lib: https://github.com/microsoft/vcpkg/blob/368313ea0e506006ca7930cae74efe14766a82d8/ports/pcl/io_ply.patch

Upstream, please choose between keeping separate libs and merging (https://github.com/miriameng/pcl/commit/25f22aee8285e1e7fb0a1dabaffa5efcc90b1186).

dg0yt avatar Mar 26 '24 09:03 dg0yt

I am running into the same issue on Windows. My workaround is additional CMake code: target_link_libraries (interactive_icp debug pcl_io_plyd optimized pcl_io_ply)

dzenanz avatar Mar 27 '24 14:03 dzenanz