My C++ project used the UniformSampling in the PCL library. It compiled and worked well. Then I copied the same code snippet into another cpp file in the same project. The errors show up
/usr/bin/ld: /media/user/docker/ramloc_ws_rel/devel/.private/radar_odometry/lib/libradar_mapping.so: undefined reference to `pcl::PCLBase<MyPointType>::initCompute()'
/usr/bin/ld: /media/user/docker/ramloc_ws_rel/devel/.private/radar_odometry/lib/libradar_mapping.so: undefined reference to `pcl::PCLBase<MyPointType>::PCLBase()'
/usr/bin/ld: /media/user/docker/ramloc_ws_rel/devel/.private/radar_odometry/lib/libradar_mapping.so: undefined reference to `pcl::PCLBase<MyPointType>::deinitCompute()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mapping_node.dir/build.make:521: /media/user/docker/ramloc_ws_rel/devel/.private/radar_odometry/lib/radar_odometry/mapping_node] Error 1
I have checked that the mapping_node and the libradar_mapping.so linked against the PCL_LIBRARIES in the CMakeLists.txt. I also added the "#define PCL_NO_PRECOMPILE" in the cpp file. The same code worked before in the project. What could be wrong?
With a bit tinkering, I found that if I placed "#define PCL_NO_PRECOMPILE" at the top of the cpp file before including any header, the linker errors went away.