试图将动态库与C ++ Xcode项目一起嵌入,但是未正确引用它们 [英] Trying to embed dynamic libraries along with C++ Xcode project, but they're not getting properly referenced

查看:109
本文介绍了试图将动态库与C ++ Xcode项目一起嵌入,但是未正确引用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在Xcode中工作,并试图使我的(C ++)命令行应用程序(Mac OS X目标)包括其自己的OpenCV动态库,以便我可以将其部署到其他人的计算机上,并且即可正确找到它们(无需在计算机上安装OpenCV).但是,除了它们在我的计算机上(/opt/local/lib)所在的位置外,它什么都没看.

I'm just starting to work in Xcode and trying to get my (C++) command-line application (Mac OS X target) to include its own dynamic libraries for OpenCV so that I can deploy to other people's computers and it'll find them properly (without their computers needing to have OpenCV installed). But it's not looking anywhere except where they live on my computer (/opt/local/lib).

当可执行文件在另一个系统上运行时,它会引发如下错误:

When the executable runs on another system, it throws errors like this:

dyld:未加载库:/opt/local/lib/libopencv_core.2.3.dylib 引用自:/Users/editc/Desktop/edge_display/edge_display原因: 找不到图片

dyld: Library not loaded: /opt/local/lib/libopencv_core.2.3.dylib Referenced from: /Users/editc/Desktop/edge_display/edge_display Reason: image not found

(请注意,尽管事实上libopencv_core.2.3.dylib与可执行文件包含在同一目录中.)

(Note that this is despite the fact that libopencv_core.2.3.dylib is included in the same directory as the executable.)

如何获取它在应用程序自己的目录中的外观?在库搜索路径中添加"./"似乎无济于事.

How do I get it to look in the application's own directory? Adding "./" to the library search paths seems to do nothing.

几次搜索表明它应该在其应用程序捆绑包的Frameworks/目录中查找,但由于某种原因它没有生成.app捆绑包,因此即使我更改了安装目录并添加了文件复制步骤,如此线程,因为我没有应用包,所以没有框架目录.因此,在没有应用程序捆绑包的情况下,该技术无法正常工作. (我不确定我什至不了解在什么条件下会生成应用捆绑包.)

Several searches have indicated that it should look in the Frameworks/ directory of its app bundle, but it's not generating an .app bundle for some reason, so even when I change the Installation Directory and add a file copy step like described in this thread, since I don't have an app bundle, I don't have a Frameworks directory. So with no app bundle, this technique isn't working. (I'm not sure I even understand under what conditions an app bundle is generated or not.)

我的项目位于此处,供您参考.有人可以帮忙吗?一般而言,我仍会继续涉足Xcode和Mac OS X开发,因此,如果这个问题看起来有些新意,请提前道歉.

My project is here, for your reference. Can anyone help? I'm still getting my feet wet in Xcode and Mac OS X development in general, so apologies in advance if this question seems neophytic.

推荐答案

一开始总是很难弄清楚这些东西.

This stuff is always hard to figure out in the beginning.

您不需要将框架复制到Frameworks目录中,因为您的项目是命令行应用程序.制作Cocoa应用程序时,只有一个应用程序包.即使在那种情况下,如果要将应用程序分发给未安装OpenCV的人,也只需要将框架复制到Frameworks目录中即可.

You don't need to copy the frameworks into the Frameworks directory because your project is a command line app. You only have an app bundle when you make a Cocoa app. And even in that case you only need to copy the frameworks into the Frameworks directory if you are going to distribute the app to people who don't have OpenCV installed.

请注意,尽管事实上libopencv_core.2.3.dylib是 与可执行文件包含在同一目录中.

Note that this is despite the fact that libopencv_core.2.3.dylib is included in the same directory as the executable.

请勿将库文件复制到可执行文件的文件夹中.只要让它链接到/opt/local/lib

Don't copy the library files into your executable file's folder. Just let it link to the files in /opt/local/lib

我下载了您的项目,并使其能够运行.这就是我所做的(使用Xcode 4):

I downloaded your project and was able to get it to run. Here's what I did (using Xcode 4):

  1. 从Edge Display文件夹中删除dylib文件(和链接)
  2. 删除复制库文件的复制文件构建阶段
  3. 删除@executable_path/../Frameworks安装目录设置
  4. 从Xcode项目的OpenCV Frameworks文件夹中删除所有内容
  5. 选择目标,选择构建阶段",展开Link Binary With Libraries
  6. 单击加号按钮,单击添加其他…",键入"/opt/local/lib",选择libopencv_core.dylib(请注意,我没有选择具有版本号的文件)
  7. 重复libopencv_highgui.dyliblibopencv_imgproc.dylib(这些是项目所需的唯一库)
  8. 将部署目标设置为OS X 10.6,因为这就是我正在使用的
  9. 点击运行并获取以下信息:
  1. Delete the dylib files (and links) from the Edge Display folder
  2. Delete the Copy Files build phase that copies the library files
  3. Delete the @executable_path/../Frameworks Installation Directory setting
  4. Delete everything from the OpenCV Frameworks folder in the Xcode project
  5. Select the target, select Build Phases, expand Link Binary With Libraries
  6. Click the plus button, click Add Other…, type "/opt/local/lib", select libopencv_core.dylib (note I didn't select a file with a version number)
  7. Repeat for libopencv_highgui.dylib and libopencv_imgproc.dylib (those are the only libraries your project needs)
  8. Set the Deployment Target to OS X 10.6 because that's what I'm using
  9. Click Run and get this:

我的系统与您的系统稍有不同,因为我的OpenCV库安装在/usr/local/lib中,但是您已经在项目的标题搜索路径中具有/opt/local/include了,所以应该没事.

My system is a little different than yours because my OpenCV libraries are installed in /usr/local/lib, but you already have /opt/local/include in the project's Header Search Path so you should be fine.

OpenCV Wiki上的OS X命令行项目中,有一些使用OpenCV库的说明. ,但它们是为Xcode 3编写的.我将尝试为Xcode 4添加一些更新的说明.

There are some instructions for using the OpenCV libraries in an OS X command-line project on the OpenCV Wiki but they're written for Xcode 3. I'll try to add some updated instructions for Xcode 4.

这篇关于试图将动态库与C ++ Xcode项目一起嵌入,但是未正确引用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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