PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.9k stars 4.61k forks source link

[windows] error linking pcl rangeimage LNK2020 LNK2001 LNK1120 #807

Open fbenavidesd opened 10 years ago

fbenavidesd commented 10 years ago

I have a visual C++ project of Dynamic Library (.dll) type. This is beacuse I want to use that C++ dll that I build from a C# project. I use your PCL library 1.6 and it works well. The problem appears when I include the range_image.h . The problem is that the RangeImage class have

static const int lookup_table_size; static std::vector asin_lookup_table; static std::vector atan_lookup_table; static std::vector cos_lookup_table;

and they are referenced by static inline method, an when you compile it like a .dll using the Common Language Runtime Support (/clr) it gives these errors

Error   80  error LNK2020: unresolved token (0A003A6D) "protected: static 
class std::vector<float,class std::allocator<float> > 
pcl::RangeImage::asin_lookup_table" 
(?asin_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) 

Error   79  error LNK2020: unresolved token (0A003A6C) "protected: static 
int const pcl::RangeImage::lookup_table_size" 
(?lookup_table_size@RangeImage@pcl@@1HB) 

Error   78  error LNK2020: unresolved token (0A003A6B) "protected: static 
class std::vector<float,class std::allocator<float> > 
pcl::RangeImage::atan_lookup_table" 
(?atan_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) 

Error   77  error LNK2020: unresolved token (0A003A6A) "protected: static 
class std::vector<float,class std::allocator<float> > 
pcl::RangeImage::cos_lookup_table" 
(?cos_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) 

Error   81  error LNK2001: unresolved external symbol "public: virtual 
void __cdecl pcl::RangeImage::getSubImage(int,int,int,int,int,class 
pcl::RangeImage &)const " 
(?getSubImage@RangeImage@pcl@@UEBAXHHHHHAEAV12@@Z) 

Error   82  error LNK2001: unresolved external symbol "public: virtual 
void __cdecl pcl::RangeImage::getHalfImage(class pcl::RangeImage 
&)const " (?getHalfImage@RangeImage@pcl@@UEBAXAEAV12@@Z) 

Error   83  error LNK2001: unresolved external symbol "protected: static 
int const pcl::RangeImage::lookup_table_size" 
(?lookup_table_size@RangeImage@pcl@@1HB) 

Error   86  error LNK2001: unresolved external symbol "protected: static 
class std::vector<float,class std::allocator<float> > 
pcl::RangeImage::cos_lookup_table" 
(?cos_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) 

Error   87  error LNK1120: 10 unresolved externals 

I found a similar problem reported at this post http://www.pcl-users.org/FW-Link-time-errors-in-RangeImage-with-clr-td3581422.html but that post is from 2011 and pcl version 1.3.0. Apparently it was solve in version 1.4.0 but I have a similar problem now with pcl version 1.6.0.

Is there a way to fix this? I'm I doing something wrong? Please, help me.

thank you for take a time to read mi question.

taketwo commented 10 years ago

I would suggest you to try compiling the library from the latest source. Then try to apply the fixes proposed in that thread.

anshulvj commented 6 years ago

I have a similar issue. I am using Visual Studio 2017 (v14) 64-bit on Win 10 64-bit. PCl 1.8 works fine on all other projects where I am using it (on Visual Studio 2013, 2017 is a recent upgrade). When I try to use RangeImage Class I get the following errors:

Error LNK1120 6 unresolved externals IRS2PlaneFitting F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\x64\Release\IRS2PlaneFitting.exe 1 Error LNK2001 unresolved external symbol "protected: static class std::vector<float,class std::allocator<float> > pcl::RangeImage::asin_lookup_table" (?asin_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) IRS2PlaneFitting F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\IRS2PlaneFitting\IRS2PlaneFitting.obj 1 Error LNK2001 unresolved external symbol "protected: static class std::vector<float,class std::allocator<float> > pcl::RangeImage::atan_lookup_table" (?atan_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) IRS2PlaneFitting

F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\IRS2PlaneFitting\IRS2PlaneFitting.obj 1 Error LNK2001 unresolved external symbol "protected: static class std::vector<float,class std::allocator<float> > pcl::RangeImage::cos_lookup_table" (?cos_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) IRS2PlaneFitting

F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\IRS2PlaneFitting\IRS2PlaneFitting.obj 1 Error LNK2001 unresolved external symbol "protected: static int const pcl::RangeImage::lookup_table_size" (?lookup_table_size@RangeImage@pcl@@1HB) IRS2PlaneFitting

F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\IRS2PlaneFitting\IRS2PlaneFitting.obj 1 Error LNK2001 unresolved external symbol "public: virtual void __cdecl pcl::RangeImage::getHalfImage(class pcl::RangeImage &)const " (?getHalfImage@RangeImage@pcl@@UEBAXAEAV12@@Z) IRS2PlaneFitting

F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\IRS2PlaneFitting\IRS2PlaneFitting.obj 1 Error LNK2001 unresolved external symbol "public: virtual void __cdecl pcl::RangeImage::getSubImage(int,int,int,int,int,class pcl::RangeImage &)const " (?getSubImage@RangeImage@pcl@@UEBAXHHHHHAEAV12@@Z) IRS2PlaneFitting

F:\IntelRealsenseDataAQ\ProcessIntelRealsense2Data\IRS2PlaneFitting\IRS2PlaneFitting.obj 1 Error (active) E1256 __w64 can only be specified on int, long, and pointer types IRS2PlaneFitting c:\wxWidgets-3.1.0_vs2017build\include\wx\defs.h 1283

I read everything I could about this error on PCL mailing list but could not find a solution link which says this bug should not be present in the latest versions. I am using 1.8. Any thoughts? If there is an easier fix than recompiling the whole pcl and dependencies and the works, that is better for me.

Thanks in advance.

patrickabadi commented 5 years ago

I had the same issue and was able to work around it. It's really strange but here's what I found:

If I returned the RangeImage through a local function I would get linker errors:

pcl::RangeImagePlanar ConvertToRangeImage (const PointCloudXYZRGBPtr & input)
{
  pcl::RangeImagePlanar rangeImage;

  return rangeImage;
}

If I just worked with the RangeImage inside a function I no longer received these linker errors:

KeypointIndicesT PclUtilities::DetectKeypoints ( const PointCloudXYZRGBPtr & input )
{
  KeypointIndicesT keypoints;

  pcl::RangeImagePlanar rangeImage;

  return keypoints;
}

Sadly, I'm not sure why it works but I hope this helps.

stale[bot] commented 4 years ago

Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.

kunaltyagi commented 4 years ago

@PointCloudLibrary/testers-windows

oliteksamuelfogarty commented 2 years ago

I'm experiencing the same problem - and like patrickabadi find this only happens if the RangeImagePlanar is being returned by a function.

AlexJOJO-ray commented 11 months ago

I have the some problem with vs2019 and PCL 1.11.1 when using the Common Language Runtime Support (/clr). I didn't use RangeImage Class, however, I got the similar error: LNK2001 unresolved external symbol "protected: static class std::vector<float,class std::allocator > pcl::RangeImage::asin_lookup_table" (?asin_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A) LNK2001 unresolved external symbol "protected: static class std::vector<float,class std::allocator > pcl::RangeImage::atan_lookup_table" (?atan_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A)
LNK2001 unresolved external symbol "protected: static class std::vector<float,class std::allocator > pcl::RangeImage::cos_lookup_table" (?cos_lookup_table@RangeImage@pcl@@1V?$vector@MV?$allocator@M@std@@@std@@A)
Are there some solutions? Thank you in advance!

windwang commented 3 months ago

same problem with vs2022 and PCL 1.14.1 when using the Common Language Runtime Support (/clr).