Open perisage opened 3 years ago
Hm, yes, I think PCL_ROOT
should be /usr
. Not sure why cmake uses the wrong path there. You could try to set PCL_DIR
manually as described in this tutorial
Well, Things are more complicated than imagined.
I set PCL_DIR
to /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake
as is shown below:
set(PCL_DIR "/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake")
find_package(PCL REQUIRED)
But the value of PCL_DIR
came back to /lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake
when find_package(PCL REQUIRED)
is invoked. Therefore, this method is not feasible.
Obviously, the value of PCL_DIR
will be reset somewhere in PCLConfig.cmake
.
So Where is the value of PCL_DIR
reset?
I noticed that the PCL_ROOT
is decided by CMAKE_CURRENT_LIST_DIR
on Linux in PCLConfig.cmake:386-392
. The source code about this conclusion is shown below:
https://github.com/PointCloudLibrary/pcl/blob/ea4d0b62d184349dbf4c245d9e79c71d070ff9fe/PCLConfig.cmake.in#L386-L392
I found the CMAKE_CURRENT_LIST_DIR
's value is /lib/x86_64-linux-gnu/cmake/pcl
on my platform. so after get_filename_component(PCL_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE)
, PCL_ROOT
became /
.
The problem is that the value of CMAKE_CURRENT_LIST_DIR
is /usr/lib/x86_64-linux-gnu/cmake/pcl
on most platform. Under this condition, PCL_ROOT
will become the correct value /usr
.
As we know that /lib
is a symbol link of /usr/lib
. Based on this, I referenced OpenCVConfig.cmake
in the OpenCV and modified the source code of PCLConfig.cmake
. The code are as follows:
file(TO_CMAKE_PATH "${PCL_DIR}" PCL_DIR)
get_filename_component(PCL_DIR "${PCL_DIR}" REALPATH)
if(WIN32 AND NOT MINGW)
# PCLConfig.cmake is installed to PCL_ROOT/cmake
get_filename_component(PCL_ROOT "${PCL_DIR}" PATH)
else()
# PCLConfig.cmake is installed to PCL_ROOT/share/pcl-x.y
# get_filename_component(PCL_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE)
get_filename_component(PCL_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
get_filename_component(PCL_ROOT "${PCL_CONFIG_PATH}/../../../../" ABSOLUTE)
endif()
Then, I can find PCL by find_package(PCL REQUIRED)
correctly and everything goes well.
So Is this special situation(CMAKE_CURRENT_LIST_DIR
was set as /lib/...
, not /usr/lib/...
) beyond PCLConfig.cmake
's consideration.
Hm, yes, I think
PCL_ROOT
should be/usr
. Not sure why cmake uses the wrong path there. You could try to setPCL_DIR
manually as described in this tutorial
I think this approach will also work on non-special systems. A PR would be appretiated @perisage
Thanks for debugging it and the nice postmortem
BTW I found this bug report: https://bugs.launchpad.net/ubuntu/+source/pcl/+bug/1896118 @perisage Out of interest, do you also use a Singularity container? Or is there anything special/uncommon about your operating system that may cause this? I am asking because Ubuntu is probably the most popular OS among PCL users, and I can't image that nobody would have noticed such a bug on a "common" Ubuntu installation.
BTW I found this bug report: https://bugs.launchpad.net/ubuntu/+source/pcl/+bug/1896118 @perisage Out of interest, do you also use a Singularity container? Or is there anything special/uncommon about your operating system that may cause this? I am asking because Ubuntu is probably the most popular OS among PCL users, and I can't image that nobody would have noticed such a bug on a "common" Ubuntu installation.
My OS is Ubuntu20.04.2 LTS which is downloaded and installed from the Ubuntu official website and there is nothing special/uncommon about it. I have tested PCL on two desktop computers with Ubuntu20.04.2 LTS and reproduced this issue on both of them.
you can use this commed to find where the real path of the PCLConfig.cmake:
sudo find / -iname "*PCLConfig*"
and then set the PCL_DIR
in the CMakeLists.txt
get_filename_component(PCL_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}" REALPATH) get_filename_component(PCL_ROOT "${PCL_CONFIG_PATH}/../../../../" ABSOLUTE)
Hi @perisage, I'm glad i found your comment as it fixed my issue!
I'm running on Ubuntu 20.04 and also came across the same issue. Here's what's weird.
When logging into ssh using VS Code remote, i was able to build the project just fine. However, when I logged into the machine via RDP and built the project using a snap installation of VS Code, cmake would fail with the same error message as described above. I just wanted to mention this, as it is apparently still an issue. I wonder, whether it is caused by different environment variables?
get_filename_component(PCL_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}" REALPATH) get_filename_component(PCL_ROOT "${PCL_CONFIG_PATH}/../../../../" ABSOLUTE)
Hi @perisage, I'm glad i found your comment as it fixed my issue!↳
I'm running on Ubuntu 20.04 and also came across the same issue. Here's what's weird.↳
When logging into ssh using VS Code remote, i was able to build the project just fine. However, when I logged into the machine via RDP and built the project using a snap installation of VS Code, cmake would fail with the same error message as described above. I just wanted to mention this, as it is apparently still an issue. I wonder, whether it is caused by different environment variables?↳
I think this is probably caused by Cmake's search mechanism ----"find_package" It will search for specific lib locations first, but where might there be no exact path. I have this problem mostly probably because I use the Cmake priority lookup path in the ROS library, but where is there only a fake address and my real pcl installation path under a characteristic folder.
hope this helps.
I have the same problem when ROS environment is activated.
Finally I found the problem,
I have /bin
before /usr/bin
is my PATH.
This cause problem! Please check it!
I installed PCL by
sudo apt install libpcl-dev
. and used it like this:some errors occurred when I built the project:
I'm trying to debug the cmake source code in
/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:418-454
, The cmake source is shown below:Through debugging, I found that the environment variable
PCL_ROOT
is set to/
andPCL_DIR
is set to/lib/x86_64-linux-gnu/cmake/pcl
. So, It can't find correct PCL include directory(the correct PCL include dir is/usr/include/pcl-1.10
) and lead to cmake error.My Environment :
So, what's the problem with my PCL, and how can I find PCL by
find_package(PCL REQUIRED)
successfully? Thanks a lot!