2013-10-09 55 views
1

我现在正在构建一个动态库和一个使用此动态库的命令行插图程序。该库和图形程序都在同一个文件夹:在mac中加载动态库路径错误

/user/xxx/develop/debug/libdynamic.dylib 
/user/xxx/develop/debug/illustration 

当插图程序可以在我的电脑上工作得很好,我发图程序以及动态库,我的同事,他会运行插图程序在他的电脑里。但是,每次他在命令窗口中运行插图程序时,程序还会提醒它无法加载libdynamic.dylib,因为它试图在我的同事的计算机中找到/user/xxx/develop/debug/中的库。我想知道我该怎么做。非常感谢。

编辑: 使用otool为了说明程序的输出如下:

/Users/xxx/develop/debug/libdynamic.dylib (compatibility version 0.0.0, current version 0.0.0) 

    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.18.0) 

    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0) 
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) 
+0

对不起,您需要'otool -L/user/xxx/develop/debug/illustration'来查看它认为'dylib'的存在位置。 – trojanfoe

回答

1

你需要告诉illustration在哪里可以找到libdynamic.dylib,你可以做使用install_name_toolmanpage)生成后。你会想新的路径设置为@executable_path/libdynamic.dylib,用(类似):

$ install_name_tool -change /user/xxx/develop/debug/libdynamic.dylib \ 
    @executable_path/libdynamic.dylib \ 
    /user/xxx/develop/debug/illustration 

(确切老字号值传递给install_name_tool将取决于什么它当前设置为,由此可确定使用otool -L /user/xxx/develop/debug/illustration)。为了避免这种废话(我做我自己的方式)

一种方法是使用-install_name链接器选项:

$(BINDIR)/libdynamic.dylib: $(OBJS) 
    $(CXX) -dynamiclib -current_version $(MAJOR_MINOR_VERSION) \ 
     -compatibility_version $(MAJOR_MINOR_VERSION) \ 
     -install_name @executable_path/libdynamic.dylib \ 
     $(LDFLAGS) -o [email protected] $(OBJS) $(LIBS) 

(从here采取Makefile片段)。