Mac上的Eclipse dyld:未加载库:未找到图像 [英] Eclipse on Mac dyld: Library not loaded: Image not found
问题描述
全部:
我已经在一个工作区(HelloWorld)中成功设置了两个项目(Hello和World)。这些是简单的项目,它们应该作为一个主要项目和一个共享库项目一起工作。这是结构:
HelloWorld
Hello
src
Hello.cpp
调试
src
你好 - [x86_64 / le]
世界
src
World.cpp
World.h
调试
src
libWorld.dylib - (x86_64 / le)
我遵循了所有的指示和终于可以让他们编译没有错误,但是当我尝试运行Hello项目时,我收到以下错误:
dyld:未加载库:libWorld.dylib
引用自:/ Users / pdl / Development / HelloWorld / Hello / Debug / Hello
原因:image not found
我发布了以下代码,它非常简单,问题(我相信)在Eclipse配置中的某个位置。
提前感谢您的帮助。
------------------ -------------- ------------ 源代码 ----------------------------- -----
Hello.cpp
#include< stdio.h>
#includeWorld.h
int main(){
printf(Hello%s\\\
,getWorld()。c_str());
return 0;
}
World.cpp
#includeWorld.h
std :: string getWorld(){returnWorld; }
World.h
#include< string>
std :: string getWorld();
dyld:库未加载:libWorld.dylib
引用自:/ Users / pdl / Development / HelloWorld / Hello / Debug / Hello
原因:image not found
这意味着您的程序正在使用名为libWorld.dylib的动态库,尽管您在编译期间将动态库与程序链接。但是你必须告诉你的程序运行时的dylib在哪里。
有两种解决方案:
解决方案1:为您的项目设置动态库环境变量在Eclipse中
:
1.点击您的项目名称
,选择运行As->运行配置
2.在环境
标签点击新
3.Put DYLD_LIBRARY_PATH
或 DYLD_FALLBACK_LIBRARY_PATH
在名称
框
4.将 libWorld.dylib
文件位于值
框
例如:
如果 libWorld.dylib
文件位于 / opt / local / lib / my_dylib
文件夹,将路径放在名称
框中
解决方案2:设置 DYLD_LIBRARY_PATH
在您的bash配置文件中
1.通常在Mac OS中,配置文件为 .profile
在〜/
文件夹下,如果没有此文件而不是创建一个名称相同的新文件
2.编辑该文件:
在您的
.profile
文件中添加此行:
export DYLD_LIBRARY_PATH = PATH_TO_YOUR_DYLIB:$ DYLD_LIBRARY_PATH
p>
在我的示例中,PATH_TO_YOUR_DYLIB是
opt / local / lib / my_dylib
,所以你只需添加:
export DYLD_LIBRARY_PATH = / opt / local / lib / my_dylib:$ DYLD_LIBRARY_PATH
在.profile文件中
这个解决方案,你不必为所有eclipse项目设置dylib路径。
PS。 DYLD_LIBRARY_PATH是一个指定动态库路径的环境变量
DYLD_LIBRARY_PATH
和 DYLD_FALLBACK_LIBRARY_PATH
请参考这个帖子
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屋!