PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.88k stars 4.61k forks source link

[LNK2019] "Pcl with surface on nurbs getting unresolved external" #5691

Open cmastelaro opened 1 year ago

cmastelaro commented 1 year ago

Describe the error

I am attempting to use the third-party library OpenNURBS from PCL while the surface-on-NURBS module is enabled, but I am experiencing some unresolved external errors. I am using PCL from VCPKG, which has been compiled for the x86-windows triplet."

pcl 1.13.0#3

I am able to link successfully with pcl_surface and use classes from pcl\surface\on_nurbs, but I am got unresolved external errors when attempting to use classes from pcl\surface\3rdparty\opennurbs.

error LNK2019: unresolved external symbol "int __cdecl ON_KnotCount(int,int)" (?ON_KnotCount@@YAHHH@Z) referenced in function _main

Here a small and simple project to test the issue: CMakeLists.txt pcl_test .txt

command line used to generate makefile considering my local paths for vcpkg pcl. cmake -G "NMake Makefiles" ..\CMakeLists.txt -DCMAKE_BUILD_TYPE=Debug -DPCL_INCLUDE_DIRS="./pcl/x86-windows/include" -DPCL_LIBRARIES="../pcl/x86-windows/debug/lib/pcl_surfaced.lib"

Despite linking all PCL libraries, I am still unable to determine the root cause of the issue.

mvieth commented 1 year ago

@cmastelaro Hi, thanks for reporting. There was a pull request recently merged on vcpkg that makes changes in exactly that part of PCL (see https://github.com/microsoft/vcpkg/pull/30996 ). So as the first step, we should find out whether that pull request caused the problem. Can you roll back to pcl 1.13.0#2 (port version 2), or can you say for sure that this problem did not appear until a few days ago?

mvieth commented 1 year ago

@cmastelaro Do you activate the surface-on-nurbs feature when installing PCL via vcpkg? Something like this: pcl[<other features>,surface-on-nurbs]:x86-windows

cmastelaro commented 1 year ago

Hi @mvieth , thank you for your reply, yes, surface-on-nurbs module is active. I'll try back-porting the pcl to pcl 1.13.0#2 and check if solve the problem. I'll let you know the results.

cmastelaro commented 1 year ago

so, looking for vcpkg package listing i find out that pcl with surface-on-nurbs module was introduced in 1.13.0#3

pcl[surface-on-nurbs][≥v1.13.0#3](https://vcpkg.link/ports/pcl/v/1.13.0/3)
Fitting NURBS to point clouds
mvieth commented 1 year ago

@cmastelaro To avoid a misunderstanding: the option surface-on-nurbs was introduced on vcpkg with 1.13.0#3. In 1.13.0#2 and earlier, there was no option to enable or disable, instead PCL always came with the surface-on-nurbs module. So if you switch to 1.13.0#2, you should (hopefully) be able to compile your program.

cmastelaro commented 1 year ago

@mvieth, thanks for the feedback i've tried with 1.13.0#1 and still getting unresolved external.

pcl_test.cpp.obj : error LNK2019: unresolved external symbol "int __cdecl ON_KnotCount(int,int)" (?ON_KnotCount@@YAHHH@Z) referenced in function _main
pcl_test.exe : fatal error LNK1120: 1 unresolved externals

I think the problem may be with the classes belonging to pcl\surface\3rdparty\opennurbs, as opposed to those belonging to pcl\surface\on_nurbs, which work as demonstrated in the example and linked with the pcl_surface library. but i'm not quite sure about that, maybe there's some output library missing, something like pcl_opennurbs.

mvieth commented 1 year ago

@cmastelaro Usually, everything should be compiled into pcl_surface. However, the way you define the include dirs and libraries in the call to cmake (-DPCL_INCLUDE_DIRS="./pcl/x86-windows/include" -DPCL_LIBRARIES="../pcl/x86-windows/debug/lib/pcl_surfaced.lib") is definitely not the recommended way. Check out our tutorial on how to use PCL with vcpkg: https://pcl.readthedocs.io/projects/tutorials/en/master/pcl_vcpkg_windows.html#using-dependencies-installed-with-vcpkg-in-cmake-projects

cmastelaro commented 1 year ago

Heads up: After conducting a series of tests, I have successfully created an external library using all opennurbs PCL surface includes and source files, that i called "opennurbs". This library links perfectly with no unresolved external at all.

mvieth commented 1 year ago

@cmastelaro Great that you found a solution that works for you. However, it would still be good if we find out what the original problem is, since pcl_surface should contain all the opennurbs stuff. Have you tried the approach recommended in the tutorial? That is: add find_package(PCL REQUIRED) in your CMakeLists.txt and specify the vcpkg toolchain file (e.g. cmake ../CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE=<your-vcpkg-path>/scripts/buildsystems/vcpkg.cmake if you use the command line)? @larshg Can you reproduce the error or do you have an idea what the problem is?

cmastelaro commented 1 year ago

Hi @mvieth, I followed the tutorial and completed all the steps, but I'm still experiencing the same issue.

main.cpp.obj : error LNK2019: unresolved external symbol "int __cdecl ON_KnotCount(int,int)" (?ON_KnotCount@@YAHHH@Z) referenced in function _main

I've noticed that the PCL surface on ONNurbs reference is working smoothly. However, I'm still encountering an 'unresolved external' error when trying to use the PCL surface with the 3rd party OpenNurbs part.