0

I am new to the Point Cloud Library. There is a thing that has been bugging me for some time.

So, on my system, whenever I have to compile a C++ program, which requires OpenCV libraries to be linked, I use the following terminal command:

g++ -std=c++11 fileName.cpp -o executableFile `pkg-config --cflags --libs opencv`

Now, things have turned to a point where I have to use PCL. But, everywhere (including the PCL's official website) people link PCL libraries using a CMake file, and I am not familiar with CMake.

Is there a way to include the PCL libraries without writing a CMake file and just including some more flags/parameters to the terminal command?

I am using Ubuntu 18.04.

  • The future proof option would seem, to me, to be to just learn `CMake`... – Jesper Juhl Jul 20 '20 at 14:36
  • Yes probably. Also, if you put that command into a shell script, you won't have to remember the command. This is useful when you add more and more libraries and the command gets longer. – user253751 Jul 20 '20 at 14:37
  • Thank you for your speedy replies. But, I am totally new to this thing. For instance, if we consider the [example](https://pcl.readthedocs.io/en/latest/using_pcl_pcl_config.html#using-pcl-pcl-config) on the PCL official website, I could not understand how pcd_write.cpp got compiled without stating any compilation parameters, like g++ -std=c++11. I would be grateful to you if you guys can help me. – Harshit Kaushik Jul 20 '20 at 14:53
  • You have to find their names, and just do '-l'. Most likely the name will be libPCLcommon. You can try to find them using **find /usr/lib -name "*PCL*.so*"**. And di you try to use pkg-config with PCL ? It can exists also, try **pkg-config --list-all** – Erwan Daniel Jul 20 '20 at 15:02
  • Thanks @ErwanDaniel. You helped me sort out one of the problems that I had. – Harshit Kaushik Jul 20 '20 at 18:08
  • Avec plaisir ! Did you successfully compiled ? – Erwan Daniel Jul 20 '20 at 19:19
  • The [PCL tutorials](https://pcl.readthedocs.io/projects/tutorials/en/latest/using_pcl_pcl_config.html) have an example CMake file you can use as a starting point – LorenzBung Jul 22 '20 at 10:51

1 Answers1

0

I experimented for a while, and here is how I figured this out.

man pkg-config tells you the folders where pkg-config looks for .pc files. So, I checked those folders for the exact .pc file names that I want pkg-config to link with my .cpp file. I found the required file (pcl_io-1.11.pc) at \usr\local\lib\pkgconfig

Next, I modified my terminal command to the following (please consider two back-quotes as a single back-quote below)

g++ -std=c++14 pcd_write.cpp -o pcd_write ``pkg-config --cflags --libs pcl_io-1.11`` -lboost_system

Note: Not including the -lboost_system would result in another error message. I found this helpful.

This compiled successfully. But, on running the executable, I would get this error message:

./pcd_write:error while loading shared libraries:libpcl_io.so.1.11:cannot open shared object file:No such file or directory

The solution to this problem was found here

sudo /sbin/ldconfig -v

Then, running the executable gave the expected results.