How to link the PCL library correctly for use in objective-C compiled in Xcode?

Question: How to use PCL in the context of Cocoa's Objective-C application (OSX, not iOS)?

Tearing my hair off of it. I cannot get libpcl to correctly reference my Objective-C project in Xcode. I checked and double-checked everything that I can think of. I’m probably doing something dumb, but I'm at a dead end.

The actual error is the linker:

Undefined symbols for architecture x86_64: "pcl::PassThrough<pcl::PointXYZ>::applyFilterIndices(std::__1::vector<int, std::__1::allocator<int> >&)", referenced from: pcl::PassThrough<pcl::PointXYZ>::applyFilter(std::__1::vector<int, std::__1::allocator<int> >&) in PCLProcess.o ld: symbol(s) not found for architecture x86_64 
  • The code I'm trying to compile is the standard tutorial code available here: http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough

  • I can make it work without Xcode (using Cmake and compiling the command line just like in the tutorial)

  • I can create a command line project and compile and link a one-time CPP file using Xcode

  • The problem is the same no matter which version of PCL I tried. Macports, a binary distribution, self-compiled 1.6 and trunk. All the same, the result.

  • I tried several different machines, OSX 10.7 and 10.8, the same thing on both.

  • I even run nm against dylib to verify that the missing characters are in the library that I am linking (in this case, filters)

Any thoughts that were highly appreciated, I lost this week for six months.

For a detailed error message, see this screenshot .

Here is the code in question:

 //PCLProcess.h #import <Foundation/Foundation.h> @interface PCLProcess : NSObject @end //PCLProcess.mm #import "PCLProcess.h" #include <pcl/point_types.h> #include <pcl/filters/passthrough.h> @implementation PCLProcess -(void)tryThis{ // Code cut and pasted from tutoral (see link above) } @end 

Update

Here is another key. I am above my head regarding compilers / linkers and how they work, but now I think I know what is happening, but not why (or how to fix it).

  • I ran the linker tool manually, and out of desperation, I started connecting obsolete checkboxes to see what the results were. The previous error (above) identifies the missing characters as "pcl :: PassThrough :: applyFilterIndices (std :: __ 1 :: vector> &)", but ld -y gave me this:

    ld: warning: -y option is obsolete and is ignored Undefined for architecture x86_64: "__ ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndicesERNSt3__16vectorIiNS3_9allocatorIiEEEE", which is referred to: __ ZN3pcl11PassThroughINS_8PointXYZEE11applyFilterERNSt3__16vectorIiNS3_9allocatorIiEEEE in PCLProcess.o ld: symbol (s) could not be found for the x86_64 architecture

So, I went looking for this symbol and, of course, it is missing (or another):

 nm /opt/local/lib/libpcl_filters.dylib | grep __ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndices 00000000000a0fa0 T __ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndicesERSt6vectorIiSaIiEE 

I suspect the name is changed? But then again, I'm not quite sure what I'm talking about now or (more importantly) how to fix it.

+2
source share
1 answer

Short answer:

Two build options in the Build Options section:

C ++ Dialog Language: GNU ++ 98 [-std = gnu ++ 98]

C ++ Standard Library: libstdC ++ (GNU C ++ Standard Library)

This second parameter (C ++ standard library) is crucial; Using libC ++ will result in the "undefined" linker errors mentioned in the question above.

Details for those trying to do this:

This works with Xcode 4.62, llvm4.2, libpcl 1.7 (currently dev, I compiled from trunk) and increase 1.53. Along the way, I ran into a known issue with Boost and Cocoa using nil (see this link: https://svn.boost.org/trac/boost/ticket/5010 ) and also some oddities with enhancements (see this: C ++: traits like Boost 1.48 and Cocoa weirdness include ). Therefore, I included the PCL headers as follows:

 #define nil Boost_nil #define Nil Boost_Nil #ifdef check #undef check #endif #include <pcl/pcl_base.h> #include <pcl/point_types.h> #include <pcl/filters/passthrough.h> #undef Nil #undef nil 
+1
source

Source: https://habr.com/ru/post/1203897/


All Articles