undefined reference when compiling a libLAS project: c++ code for a LAS to PCD converter

667 views Asked by At

I'm trying to write a simple file converter, to convert 3d point clouds from LAS to PCD file formats. I am using Ubuntu 16.04. I have successfully compiled and installed PCL 1.8 and liblas 1.8.1. I have tested this by compiling and running a simple pcd-tutorial and have executed lasinfo to output the information of a given las file.

I now want to compile one of the liblas tutorials but it fails in the first line in which I use any of the liblas functions. I suspect it has something to do with the linking of the library but I have hardly any experience with this. This is the error message I get:

/home/icedoggy/Documents/QtConsoleTestApp/TestApp/main.cpp:21: error: undefined reference to `liblas::Reader::Reader(std::istream&)' and i get this for all otherlines containing liblas:: ...

The path to the include dir seems to be correct and the code-completion works when i type: liblas:: list of function appears.

Update/Edit: The updated code now contains pcl and liblas headers and uses these libraries. A las-file is read in and saved as a pcd file. This may be helpful to others, therefore I post it here. The problem I had was, however, not realted to the source code but to the way the liblas library was included into the QT-project. I have now changed to a cmake project and the CMakeLists.txt is provided below as well.

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

#include <liblas/liblas.hpp>
#include <fstream>  // std::ifstream

int  main (int argc, char** argv){

pcl::PointCloud<pcl::PointXYZI> cloud;

  // reading data from LAS file:
  // 1) create a file stream object to access the file

std::ifstream ifs;
ifs.open("~/DATASETS/20140320-1-1.las", std::ios::in |     std::ios::binary);

  liblas::ReaderFactory f;  
  liblas::Reader reader = f.CreateWithStream(ifs);

  liblas::Header const& header = reader.GetHeader();

  long int nPts = header.GetPointRecordsCount();
  std::cout << "Compressed: " << (header.Compressed() == true) ? "true\n":"false\n";
  std::cout << "\nSignature: " << header.GetFileSignature() << '\n';
  std::cout << "Points count: " << nPts << '\n';



  // Fill in the PCD cloud data
  cloud.width    = nPts;
  cloud.height   = 1;
  cloud.is_dense = true;
  cloud.points.resize (cloud.width * cloud.height);

  while (reader.ReadNextPoint()){
        liblas::Point const& p = reader.GetPoint();

    cloud.points[i].x = p.GetX();
    cloud.points[i].y = p.GetY();
    cloud.points[i].z = p.GetZ();
    cloud.points[i].intensity = p.GetIntensity();

}

// save data to pcd file in ascii format.
  pcl::io::savePCDFileASCII ("output_in_pcdformat.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points ." << std::endl;

   return (0);
}

Resources I have used for the code above are: https://www.liblas.org/tutorial/cpp.html and http://pointclouds.org/documentation/tutorials/writing_pcd.php as well as https://cmake.org/cmake-tutorial/ for cmake (see below).

Okay as mentioned by some comments I have adapted the post. I did a bit of reading on cmake as I don't like to get into QT-creator specifics as most of my other projects are also cmake projects. The problem that I had was that, I did not link the libLAS libraries in my qt-project (or the way I had tried to do that did not work). This is how I solved the problem with cmake. Lines with ** are the one related to my problem.

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(pcd_write)
find_package(PCL 1.7 REQUIRED)
**find_package(libLAS REQUIRED)**
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcd_write pcd_write.cpp)
**target_link_libraries (pcd_write ${PCL_LIBRARIES} ${libLAS_LIBRARIES})**
0

There are 0 answers