pcl
pcl copied to clipboard
[compile error] "RangeImageSpherical link error in windows"
Describe the error
range_image_visualization.cpp.obj : error LNK2001: 无法解析的外部符号 "public: virtual void __cdecl pcl::RangeImage::getSubImage(int,int,int,int,int,class pcl::RangeImage &)const " (?getSubImage@RangeImage@pcl@@UEBAXHHHHHAEAV12@@Z)
range_image_visualization.cpp.obj : error LNK2001: 无法解析的外部符号 "public: virtual void __cdecl pcl::RangeImage::getHalfImage(class pcl::RangeImage &)const " (?getHalfImage@RangeImage@pcl@@UEBAXAEAV12@@Z)
range_image_visualization.cpp.obj : error LNK2019: 无法解析的外部符号 "protected: static int const pcl::RangeImage::lookup_table_size" (?lookup_table_size@RangeImage@pcl@@1HB),函数 "protected: static float __cdecl pcl::RangeImage::asinLookUp(float)" (?asinLookUp@RangeImage@pcl@@KAMM@Z) 中引用了该符号
range_image_visualization.cpp.obj : error LNK2019: 无法解析的外部符号 "protected: static class std::vector<float,class std::allocator
To Reproduce
Screenshots/Code snippets/Build information
#include <iostream>
#include <pcl/range_image/range_image.h>
#include <pcl/range_image/range_image_spherical.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/range_image_visualizer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
typedef pcl::PointXYZ PointType;
// --------------------
// -----Parameters-----
// --------------------
float angular_resolution_x = 0.5f,
angular_resolution_y = angular_resolution_x;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
bool live_update = false;
// --------------
// -----Help-----
// --------------
void
printUsage (const char* progName)
{
std::cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n"
<< "Options:\n"
<< "-------------------------------------------\n"
<< "-rx <float> angular resolution in degrees (default "<<angular_resolution_x<<")\n"
<< "-ry <float> angular resolution in degrees (default "<<angular_resolution_y<<")\n"
<< "-c <int> coordinate frame (default "<< (int)coordinate_frame<<")\n"
<< "-l live update - update the range image according to the selected view in the 3D viewer.\n"
<< "-h this help\n"
<< "\n\n";
}
void
setViewerPose (pcl::visualization::PCLVisualizer& viewer, const Eigen::Affine3f& viewer_pose)
{
Eigen::Vector3f pos_vector = viewer_pose * Eigen::Vector3f(0, 0, 0);
Eigen::Vector3f look_at_vector = viewer_pose.rotation () * Eigen::Vector3f(0, 0, 1) + pos_vector;
Eigen::Vector3f up_vector = viewer_pose.rotation () * Eigen::Vector3f(0, -1, 0);
viewer.setCameraPosition (pos_vector[0], pos_vector[1], pos_vector[2],
look_at_vector[0], look_at_vector[1], look_at_vector[2],
up_vector[0], up_vector[1], up_vector[2]);
}
// --------------
// -----Main-----
// --------------
int
main (int argc, char** argv)
{
// --------------------------------------
// -----Parse Command Line Arguments-----
// --------------------------------------
if (pcl::console::find_argument (argc, argv, "-h") >= 0)
{
printUsage (argv[0]);
return 0;
}
if (pcl::console::find_argument (argc, argv, "-l") >= 0)
{
live_update = true;
std::cout << "Live update is on.\n";
}
if (pcl::console::parse (argc, argv, "-rx", angular_resolution_x) >= 0)
std::cout << "Setting angular resolution in x-direction to "<<angular_resolution_x<<"deg.\n";
if (pcl::console::parse (argc, argv, "-ry", angular_resolution_y) >= 0)
std::cout << "Setting angular resolution in y-direction to "<<angular_resolution_y<<"deg.\n";
int tmp_coordinate_frame;
if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0)
{
coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame);
std::cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n";
}
angular_resolution_x = pcl::deg2rad (angular_resolution_x);
angular_resolution_y = pcl::deg2rad (angular_resolution_y);
// ------------------------------------------------------------------
// -----Read pcd file or create example point cloud if not given-----
// ------------------------------------------------------------------
pcl::PointCloud<PointType>::Ptr point_cloud_ptr (new pcl::PointCloud<PointType>);
pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr;
Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());
std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd");
if (!pcd_filename_indices.empty ())
{
std::string filename = argv[pcd_filename_indices[0]];
if (pcl::io::loadPCDFile (filename, point_cloud) == -1)
{
std::cout << "Was not able to open file \""<<filename<<"\".\n";
printUsage (argv[0]);
return 0;
}
scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0],
point_cloud.sensor_origin_[1],
point_cloud.sensor_origin_[2])) *
Eigen::Affine3f (point_cloud.sensor_orientation_);
}
else
{
std::cout << "\nNo *.pcd file given => Generating example point cloud.\n\n";
for (float x=-0.5f; x<=0.5f; x+=0.01f)
{
for (float y=-0.5f; y<=0.5f; y+=0.01f)
{
PointType point; point.x = x; point.y = y; point.z = 2.0f - y;
point_cloud.push_back (point);
}
}
point_cloud.width = point_cloud.size (); point_cloud.height = 1;
}
// -----------------------------------------------
// -----Create RangeImage from the PointCloud-----
// -----------------------------------------------
float noise_level = 0.0;
float min_range = 0.0f;
int border_size = 1;
// pcl::RangeImage::Ptr range_image_ptr(new pcl::RangeImage);
auto range_image_ptr = pcl::make_shared<pcl::RangeImageSpherical>();
pcl::RangeImage& range_image = *range_image_ptr;
range_image.createFromPointCloud (point_cloud, angular_resolution_x, angular_resolution_y,
pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),
scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
// --------------------------------------------
// -----Open 3D viewer and add point cloud-----
// --------------------------------------------
pcl::visualization::PCLVisualizer viewer ("3D Viewer");
viewer.setBackgroundColor (1, 1, 1);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 0, 0, 0);
viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");
viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image");
//viewer.addCoordinateSystem (1.0f, "global");
//PointCloudColorHandlerCustom<PointType> point_cloud_color_handler (point_cloud_ptr, 150, 150, 150);
//viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");
viewer.initCameraParameters ();
setViewerPose(viewer, range_image.getTransformationToWorldSystem ());
// --------------------------
// -----Show range image-----
// --------------------------
// pcl::visualization::RangeImageVisualizer range_image_widget ("Range image");
// range_image_widget.showRangeImage (range_image);
//--------------------
// -----Main loop-----
//--------------------
while (!viewer.wasStopped ())
{
// range_image_widget.spinOnce ();
viewer.spinOnce ();
pcl_sleep (0.01);
// if (live_update)
// {
// scene_sensor_pose = viewer.getViewerPose();
// range_image.createFromPointCloud (point_cloud, angular_resolution_x, angular_resolution_y,
// pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),
// scene_sensor_pose, pcl::RangeImage::LASER_FRAME, noise_level, min_range, border_size);
// range_image_widget.showRangeImage (range_image);
// }
}
}
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(range_image_visualization)
find_package(PCL 1.12 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
if (${PCL_VERSION} VERSION_EQUAL "1.12.0" AND MSVC)
# Add avx flags to fix bug,
# see github.com/PointCloudLibrary/pcl/issues/4859,
# github.com/PointCloudLibrary/pcl/issues/5003
# github.com/PointCloudLibrary/pcl/issues/4698
set(AVX_FLAGS "/arch:AVX2 /arch:AVX")
message(STATUS "Add avx flags: ${AVX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
endif ()
add_executable (range_image_visualization range_image_visualization.cpp)
target_link_libraries (range_image_visualization ${PCL_LIBRARIES})
Your Environment (please complete the following information):
- OS: [Win10]
- Compiler: [Visual Studio 2019]
- PCL Version [1.12.0] (NB: please ensure you don't have multiple versions available: I have only this version)
- PCL Type: [Installed]
Additional context
When I use RangeImage, everything is ok(except for the visualization of range image, so I commnet relative code), but when I use RangeImageShperical, the link error occuored.
The code is the PCL tutorial code of "How to visualize range image”
I tested the code you posted under Ubuntu 21.10 (gcc 11.2.0), and it compiled successfully. So this might be an MSVC-only issue. How did you install PCL? With vcpkg or the all-in-one installer or some other way?
I use the all-in-one installer
@larshg Could you have a look at this? Seems to be Windows-only