如何正确链接PCL库以在Xcode中编译的Objective-C应用程序中使用? [英] How do I link PCL library properly for use within an objective-C app compiled in Xcode?

查看:305
本文介绍了如何正确链接PCL库以在Xcode中编译的Objective-C应用程序中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

把头发弄干了.我不能让libpcl正确地与Xcode中的Objective C项目链接.我已经检查并重新检查了我可能想到的所有内容.可能在做一些愚蠢的事情,但我很沮丧.

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.

实际错误是链接器:

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

  • 我要编译的代码是此处提供的标准教程代码: http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough

    • The code I'm trying to compile is the standard tutorial code available here: http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough

      我可以在没有Xcode的情况下使其正常工作(完全按照本教程中的说明使用Cmake和命令行编译)

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

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

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

      无论我尝试使用哪个版本的PCL,问题都是相同的. Macports,二进制发行版,自编译1.6和主干.都是一样的结果.

      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.

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

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

      我甚至对dylib运行nm来验证丢失的符号是否在我链接的库中(在这种情况下为过滤器)

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

      任何人都非常感激,我已经失去了半个星期.

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

      有关详细的错误消息,请参见此屏幕截图.

      See this screenshot for a detailed error message.

      这是有问题的代码:

      //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).

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

      • 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:

      ld:警告:选项-y已过时且被忽略 架构x86_64的未定义符号:"__ ZN3pcl11PassThroughINS_8PointXYZEE11applyFilterERNSt3__16vectorIiNSEoEE3o9 PCILNS3_9分配器. ld:找不到架构x86_64的符号

      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

      因此,我去寻找该符号,并且肯定地,它已丢失(或不同):

      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.

      推荐答案

      简短答案:

      构建选项"下的两个构建设置:

      Short answer:

      Two Build settings under "Build Options":

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

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

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

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

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

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

      这适用于Xcode 4.62,llvm4.2,libpcl 1.7(当前为dev,我是从trunk编译的)和boost 1.53.一路上,我遇到了Boost和Cocoa涉及使用nil的已知问题(请参见以下链接: c ++:Boost 1.48型性状和可可粉夹杂物)因此,我最终将PCL标头包括如下:

      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:

      #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
      

      这篇关于如何正确链接PCL库以在Xcode中编译的Objective-C应用程序中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆