C++ 在mac中加载动态库路径错误
我现在正在构建一个动态库和一个使用该动态库的命令行演示程序。库和插图程序位于同一文件夹中:C++ 在mac中加载动态库路径错误,c++,xcode,macos,shared-libraries,C++,Xcode,Macos,Shared Libraries,我现在正在构建一个动态库和一个使用该动态库的命令行演示程序。库和插图程序位于同一文件夹中: /user/xxx/develop/debug/libdynamic.dylib /user/xxx/develop/debug/illustration 当插图程序可以在我的计算机中很好地工作时,我将插图程序和动态库发送给我的同事,他将在他的计算机中运行插图程序。但是,每次他在命令窗口中运行插图程序时,该程序也会提醒无法加载libdynamic.dylib,因为它试图在/user/xxx/develo
/user/xxx/develop/debug/libdynamic.dylib
/user/xxx/develop/debug/illustration
当插图程序可以在我的计算机中很好地工作时,我将插图程序和动态库发送给我的同事,他将在他的计算机中运行插图程序。但是,每次他在命令窗口中运行插图程序时,该程序也会提醒无法加载libdynamic.dylib
,因为它试图在/user/xxx/develope/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)
您需要告诉
插图
在哪里可以找到libdynamic.dylib
,您可以使用install_name_tool
()进行后期构建。您需要将新路径设置为@executable\u path/libdynamic.dylib
,如下所示:
(要传递给安装\u name\u工具
的确切旧名称值将取决于当前设置的内容,可以使用otool-L/user/xxx/develope/debug/illustration
确定)
避免这种胡说八道的一种方法(我自己也是这么做的)是使用-install\u 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
fragment取自)。您需要告诉插图
在哪里可以找到libdynamic.dylib
,您可以使用install_name_tool
()进行后期构建。您需要将新路径设置为@executable\u path/libdynamic.dylib
,如下所示:
(要传递给安装\u name\u工具
的确切旧名称值将取决于当前设置的内容,可以使用otool-L/user/xxx/develope/debug/illustration
确定)
避免这种胡说八道的一种方法(我自己也是这么做的)是使用-install\u 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
fragment取自)。很抱歉,您需要otool-L/user/xxx/develope/debug/illustration
查看它认为dylib
存在的位置。很抱歉,您需要otool-L/user/xxx/develope/debug/illustration
查看它认为dylib
存在的位置。