我现在正在构建一个动态库和一个使用此动态库的命令行插图程序。库和插图程序位于同一文件夹中:
/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 :(得分:1)
您需要告诉illustration
在哪里找到libdynamic.dylib
,您可以使用install_name_tool
(manpage)进行后期制作。您需要将新路径设置为@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 $@ $(OBJS) $(LIBS)
(Makefile
片段取自here)。