OSX 框架链接问题

发布于 2024-10-16 06:48:30 字数 865 浏览 1 评论 0原文

我正在开发 OSX 10.6 的私有框架,其中包括一些命令行工具以及一些 dylib。现在,dylib 需要相互链接,并且命令行工具需要链接 dylib。

命令行工具和 .dylibs 位于框架包内的 Resources 文件夹内。我已使用 install_name_tool 将所有路径更新为:

@executable_path/../Frameworks/MyCompany.framework/Versions/A/Resources/lib.dylib

现在,所有 dylib 在应用程序使用时都能正确加载,但命令行工具在运行时会失败,并显示 dyld: Library not returned code> 运行时如下:

// dylibpath is an NSString set the the path of the Resources folder within the framework

NSTask *task = [[[NSTask alloc]init]autorelease];
[task setEnvironment:[NSDictionary dictionaryWithObjectsAndKeys:@"DYLD_LIBRARY_PATH", dylibPath, nil]];
[task setLaunchPath:binConvert];
[task launch];
[task waitUntilExit];

现在,我来自 Windows 背景,如果 DLL 驻留在与应用程序相同的文件夹中,则加载程序会找到 DLL,但显然 OSX 会查找完整路径。如何使用命令行工具在同一文件夹中查找 dylib?

谢谢, J

I'm working on a private framework for OSX 10.6 which includes some command line tools as well as some dylibs. Now, the dylibs need to link against each other and the command line tools need to link against the dylibs.

The command line tools and the .dylibs are inside the Resources folder inside the framework bundle. I've used install_name_tool to update all the paths to:

@executable_path/../Frameworks/MyCompany.framework/Versions/A/Resources/lib.dylib

Now, all the dylibs load correctly when used by an application but the command line tools when run fail with dyld: Library not loaded when run as follows:

// dylibpath is an NSString set the the path of the Resources folder within the framework

NSTask *task = [[[NSTask alloc]init]autorelease];
[task setEnvironment:[NSDictionary dictionaryWithObjectsAndKeys:@"DYLD_LIBRARY_PATH", dylibPath, nil]];
[task setLaunchPath:binConvert];
[task launch];
[task waitUntilExit];

Now, I come from a Windows background where the loader would find the DLLs if they reside in the same folder as the app but obviously OSX looks for a complete path. How can I get the command line tool to find the dylibs in the same folder?

Thanks,
J

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有木有妳兜一样 2024-10-23 06:48:30

我可以想到尝试两件事。

选项一

使用 @rpath 可能更适合您想要做的事情。这里发生的事情是这样的:

您的库都希望它们相对于任何可执行文件的定位相同。它们都将位于:

@executable_path/../Frameworks/MyCompany.framework/Versions/A/Resources/lib.dylib

只要将所有库放在相对于可执行文件的正确位置,您就可以使其工作。相反,您可以将 dylib 上的安装名称(通过 install_name_tool)设置为 @rpath/lib.dylib。然后,这应该与 DYLD_LIBRARY_PATH 环境变量一起使用,但它确实适合与 -rpath 编译器标志一起使用,因此这可能有效,但我从未尝试过。

选项二

您还可以创建符号链接,以便通过从可执行文件遍历您设置为安装名称的路径来实际找到该库。

There are two things I can think of to try.

Option one

Using @rpath might be better suited for what you're trying to do. What's happening here is this:

Your libraries all expect that they will be positioned the same relative to whatever executable. They're all going to be at:

@executable_path/../Frameworks/MyCompany.framework/Versions/A/Resources/lib.dylib

Which you could make work as long as you put all your libraries in the right place relative to the executables. Instead, you can set the install name on the dylibs (via install_name_tool) to @rpath/lib.dylib. This should then work with the DYLD_LIBRARY_PATH environment variable, but it's really suited for use with the -rpath compiler flag, so this may work, but I've never tried it.

Option two

You can also create symbolic links so that the library will actually be found by traversing from the executables to through the path you've set as the install name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文