Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tsijs opened this issue Sep 24, 2020 · 13 comments · Fixed by #6205
Labels
kind: compile error Type of issue status: triage Labels incomplete

Comments

@tsijs
Copy link

tsijs commented Sep 24, 2020

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

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 tsijs added kind: compile error Type of issue status: triage Labels incomplete labels Sep 24, 2020
@wyhao31
Copy link

wyhao31 commented Dec 2, 2020

Same problem here.

@tsijs , do you have a solution now?

@alokpr
Copy link

alokpr commented Dec 2, 2020

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

@tsijs
Copy link
Author

tsijs commented Dec 18, 2020

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}
}

@jasjuang
Copy link
Contributor

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

@JackBoosY
Copy link
Contributor

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.

@themightyoarfish
Copy link
Contributor

themightyoarfish commented Jan 13, 2022

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?

@liuzhy71
Copy link

same error for me, any progress?

@larshg
Copy link
Contributor

larshg commented Mar 15, 2022

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.

miriameng added a commit to miriameng/pcl that referenced this issue Mar 6, 2023
@dg0yt
Copy link
Contributor

dg0yt commented Mar 25, 2024

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
Copy link
Contributor

dg0yt commented Mar 26, 2024

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 (miriameng@25f22ae).

@dzenanz
Copy link
Contributor

dzenanz commented Mar 27, 2024

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)

@HernandoR
Copy link

run into the issue on linux with vcpkg:(2968c141e31261d374f93b3dae9e6ea1d30004bf) has vcpkg update their version?

@dg0yt
Copy link
Contributor

dg0yt commented Jan 15, 2025

run into the issue on linux with vcpkg:(2968c141e31261d374f93b3dae9e6ea1d30004bf) has vcpkg update their version?

2968c141e31261d374f93b3dae9e6ea1d30004bf is 1.14.1#3 which includes the suggested patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: compile error Type of issue status: triage Labels incomplete
Projects
None yet
Development

Successfully merging a pull request may close this issue.