如何正确链接PCL库以在Xcode中编译的Objective-C应用程序中使用?

时间:2022-09-07 08:09:02

Question: How do I use PCL in the context of an Objective-C Cocoa (OSX, not iOS) app?

问题:如何在Objective-C Cocoa(OSX,而​​不是iOS)应用程序的上下文中使用PCL?

Tearing my hair out over this one.I can't get libpcl to link properly with my Objective C project in Xcode. I have checked and re-checked everything I can possibly think of. Probably doing something dumb, but I'm stumped.

撕掉我的头发。我无法让libpcl与我在Xcode中的Objective C项目正确链接。我检查并重新检查了我能想到的一切。可能做一些蠢事,但我很难过。

Actual error is 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

    我正在尝试编译的代码是这里提供的标准教程代码:http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough

  • I CAN get it to work without Xcode (using Cmake and command line compiling exactly as in the tutorial)

    我可以在没有Xcode的情况下使用它(完全按照教程中的使用Cmake和命令行编译)

  • I CAN create a "command line" project and compile and link a one-off CPP file using Xcode

    我可以创建一个“命令行”项目,并使用Xcode编译和链接一次性CPP文件

  • The issue is the same no matter what version of PCL I've tried. Macports, binary distro, self-compiled 1.6 and trunk. All the same result.

    无论我尝试过什么版本的PCL,问题都是一样的。 Macports,二进制发行版,自编1.6和trunk。所有相同的结果。

  • I've tried several different machines, OSX 10.7 and 10.8, same issue on both.

    我已经尝试了几种不同的机器,OSX 10.7和10.8,两者都有相同的问题。

  • I've even run nm against the dylib to verify the missing symbols are in the library I'm linking (filters in this case)

    我甚至对dylib运行nm以验证我正在链接的库中缺少的符号(在这种情况下是过滤器)

Any thoughts much appreciated, I've lost half a week to this.

任何想法都非常感激,我已经失去了半个星期。

See this screenshot for a detailed error message.

请参阅此屏幕截图以获取详细的错误消息

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 one more clue. I am in over my head with respect to 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 plugging in obsolete flags just to see what the results were. The previous error (above) identifies the missing symbols as ""pcl::PassThrough::applyFilterIndices(std::__1::vector >&)" but ld -y gave me this:

    我手动运行了链接器工具,出于绝望,我开始插入过时的标志只是为了看看结果是什么。上一个错误(上面)将缺少的符号标识为“”pcl :: PassThrough :: applyFilterIndices(std :: __ 1 :: vector>&)“但是ld -y给了我这个:

    ld: warning: option -y is obsolete and being ignored Undefined symbols for architecture x86_64:"__ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndicesERNSt3__16vectorIiNS3_9allocatorIiEEEE", referenced from:__ZN3pcl11PassThroughINS_8PointXYZEE11applyFilterERNSt3__16vectorIiNS3_9allocatorIiEEEE in PCLProcess.o ld: symbol(s) not found for architecture x86_64

    LD:警告:选项-y是过时的,被忽略的建筑x86_64的未定义符号:找不到架构x86_64的符号(S):“__ ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndicesERNSt3__16vectorIiNS3_9allocatorIiEEEE”,从引用:__ ZN3pcl11PassThroughINS_8PointXYZEE11applyFilterERNSt3__16vectorIiNS3_9allocatorIiEEEE在PCLProcess.o LD

So then I went looking for that symbol and, sure enough, it's missing (or different):

那么我去找那个符号,当然,它缺少(或不同):

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

I suspect name mangling? But again, I'm not really sure what I'm talking about at this point or (more importantly) how to fix it.

我怀疑名字错了吗?但同样,我不确定我在谈论的是什么,或者(更重要的是)如何解决它。

1 个解决方案

#1


1  

Short answer:

Two Build settings under "Build Options":

“构建选项”下的两个构建设置:

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

C ++语言方言:GNU ++ 98 [-std = gnu ++ 98]

C++ Standard Library: libstdc++ (GNU C++ standard library)

C ++标准库:libstdc ++(GNU C ++标准库)

This second setting (C++ Standard Library) is the crucial one; Using libc++ will produce the "undefined symbols" linker errors shown in the question above.

第二个设置(C ++标准库)是至关重要的设置;使用libc ++将产生上述问题中显示的“未定义符号”链接器错误。

Details for anyone trying this:

This works with Xcode 4.62, llvm4.2, libpcl 1.7 (currently dev, I compiled from trunk) and boost 1.53. Along the way I ran into a known issue with Boost and Cocoa involving the use of nil (see this link:https://svn.boost.org/trac/boost/ticket/5010) and also some strangeness with boost traits (see this:c++: Boost 1.48 type traits and Cocoa inclusion weirdness) Consequently I ended up including PCL headers as follows:

这适用于Xcode 4.62,llvm4.2,libpcl 1.7(当前dev,我从trunk编译)和boost 1.53。一路上我遇到了Boost和Cocoa的一个已知问题,涉​​及使用nil(参见此链接:https://svn.boost.org/trac/boost/ticket/5010)以及一些带有提升特征的陌生感(参见这个:c ++:Boost 1.48类型特征和Cocoa包含怪异)因此我最终包括PCL头文件如下:

#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


1  

Short answer:

Two Build settings under "Build Options":

“构建选项”下的两个构建设置:

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

C ++语言方言:GNU ++ 98 [-std = gnu ++ 98]

C++ Standard Library: libstdc++ (GNU C++ standard library)

C ++标准库:libstdc ++(GNU C ++标准库)

This second setting (C++ Standard Library) is the crucial one; Using libc++ will produce the "undefined symbols" linker errors shown in the question above.

第二个设置(C ++标准库)是至关重要的设置;使用libc ++将产生上述问题中显示的“未定义符号”链接器错误。

Details for anyone trying this:

This works with Xcode 4.62, llvm4.2, libpcl 1.7 (currently dev, I compiled from trunk) and boost 1.53. Along the way I ran into a known issue with Boost and Cocoa involving the use of nil (see this link:https://svn.boost.org/trac/boost/ticket/5010) and also some strangeness with boost traits (see this:c++: Boost 1.48 type traits and Cocoa inclusion weirdness) Consequently I ended up including PCL headers as follows:

这适用于Xcode 4.62,llvm4.2,libpcl 1.7(当前dev,我从trunk编译)和boost 1.53。一路上我遇到了Boost和Cocoa的一个已知问题,涉​​及使用nil(参见此链接:https://svn.boost.org/trac/boost/ticket/5010)以及一些带有提升特征的陌生感(参见这个:c ++:Boost 1.48类型特征和Cocoa包含怪异)因此我最终包括PCL头文件如下:

#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