Mac上的Eclipse dyld:未加载库:找不到图像 [英] Eclipse on Mac dyld: Library not loaded: Image not found

查看:862
本文介绍了Mac上的Eclipse dyld:未加载库:找不到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部:



我已经在一个工作区(HelloWorld)中成功设置了两个项目(Hello和World)。这些是简单的项目,应该一起作为一个主要项目和一个共享库项目。这是结构:

  HelloWorld 
Hello
src
Hello.cpp
Debug
src
Hello - [x86_64 / le]
World
src
World.cpp
World.h
Debug
src
libWorld.dylib - (x86_64 / le]

但是,当我试图运行Hello项目时,我收到以下错误:

  dyld:库未加载:libWorld.dylib 
引用自:/ Users / pdl / Development / HelloWorld / Hello / Debug / Hello
原因:找不到图片

我发布了下面的代码,它是超级简单,问题(我相信)是在Eclipse配置中的某个地方。



预先感谢您的帮助。



------------------ -------------------------- 源代码 --------------- -------------------



Hello.cpp

  #include< stdio.h> 
#includeWorld.h

int main(){
printf(Hello%s\\\
,getWorld()。c_str());
return 0;
}

World.cpp
$ b

  #includeWorld.h

std :: string getWorld(){returnWorld; }

World.h

  #include< string> 

std :: string getWorld();


解决方案

  dyld:库未加载:libWorld.dylib 
引用自:/ Users / pdl / Development / HelloWorld / Hello / Debug / Hello
原因:未找到图片
pre>

这意味着您的程序正在使用一个名为libWorld.dylib的动态库,尽管您在编译期间将动态库链接到您的程序。但是你必须告诉你的程序在运行时dylib在哪里。



有两种解决方案:



解决方案1:为项目设置动态库环境变量在Eclipse



1.右键单击您的项目名称 运行As->运行配置



2.Under 环境 tab



3.Put DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH



路径 libWorld.dylib 文件位于



例如:
if libWorld.dylib 文件位于 / opt / local / lib / my_dylib 文件夹,而不是将路径放在名称框中



解决方案2:设置 DYLD_LIBRARY_PATH



1.正常情况下,在Mac OS中,配置文件为 .profile 〜/ 文件夹下,如果您没有此文件,请创建一个相同名称的新文件



2.编辑该文件:


.profile 文件中添加此行:
export DYLD_LIBRARY_PATH = PATH_TO_YOUR_DYLIB:$ DYLD_LIBRARY_PATH



在我的示例中,PATH_TO_YOUR_DYLIB opt / local / lib / my_dylib ,所以你只需添加:
export DYLD_LIBRARY_PATH = / opt / local / lib / my_dylib:$ DYLD_LIBRARY_PATH
in .profile file


3.问题解决了,在这个解决方案中,你不必为所有eclipse项目设置dylib路径



PS。 DYLD_LIBRARY_PATH是一个环境变量,用于指定动态库的路径



DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH 请参阅 this post


All:

I have successfully set up two projects (Hello and World) in one workspace (HelloWorld). These are simple projects that are supposed to work together as a main project and a shared library project. This is the structure:

HelloWorld
    Hello
        src
            Hello.cpp
        Debug
            src
            Hello - [x86_64/le]
    World
        src
            World.cpp
            World.h
        Debug
            src
            libWorld.dylib - (x86_64/le]

I have followed all instructions and finally was able to get them to compile with no errors. However, when I try to run the Hello project I receive the following error:

dyld: Library not loaded: libWorld.dylib
  Referenced from: /Users/pdl/Development/HelloWorld/Hello/Debug/Hello
  Reason: image not found

I posted the code below. It is super simple and the problem (I believe) is somewhere in the Eclipse configuration.

Thank you in advance for your help.

-------------------------------------------- Source Code ----------------------------------

Hello.cpp

#include <stdio.h>
#include "World.h"

int main() {
  printf("Hello %s\n", getWorld().c_str());
  return 0;
}

World.cpp

#include "World.h"

std::string getWorld() { return "World"; }

World.h

#include <string>

std::string getWorld();

解决方案

dyld: Library not loaded: libWorld.dylib
Referenced from: /Users/pdl/Development/HelloWorld/Hello/Debug/Hello
Reason: image not found

This means that your program is using a dynamic library called libWorld.dylib, although you linked your dynamic library to your program during compiling. But you have to tell your program where is the dylib in run-time.

There are two solutions:

Solution 1: set up dynamic library environment variables for your project in Eclipse:

1.Right click your project name, select Run As->Run Configuration

2.Under Environment tab click New

3.Put DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH in Name box

4.Put the path where your libWorld.dylib file is in Value box

For example: if libWorld.dylib file is in /opt/local/lib/my_dylib folder, than put the path in the Name box

Solution 2: set DYLD_LIBRARY_PATH in your bash configuration file

1.Normally in Mac OS, configuration file is .profile under ~/ folder, if you don't have this file than create a new file with the same name

2.Edit that file:

Add this line in your .profile file: export DYLD_LIBRARY_PATH=PATH_TO_YOUR_DYLIB:$DYLD_LIBRARY_PATH

in my example the PATH_TO_YOUR_DYLIB is opt/local/lib/my_dylib, so you just add: export DYLD_LIBRARY_PATH=/opt/local/lib/my_dylib:$DYLD_LIBRARY_PATH in .profile file

3.Problem solved, in this solution, you don't have to set up dylib path for all eclipse project

PS. DYLD_LIBRARY_PATH is an environment variable to specify the path of your dynamic library

Difference between DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH please refer to this post

这篇关于Mac上的Eclipse dyld:未加载库:找不到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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