(mac C++开发),对于动态库,其中是否在Makefile.am脚本中指定了install_name?

问题描述:

我正在使用mac上的gnu autotools构建一个项目。一切都编译好,但我有问题链接到动态库。如何在我的Makefile.am脚本中指定install_name。我想这可能是类似以下内容:(mac C++开发),对于动态库,其中是否在Makefile.am脚本中指定了install_name?

lib_LTLIBRARIES = libphysics.la 

    libphysics_la_SOURCES = PhysicsEngine.cpp\ 
     PointMass.cpp\ 
     Spring.cpp\ 
     WaterForceGenerator.cpp 

    AM_CPPFLAGS= @[email protected]\ 
     -I../include\ 
     -Iinclude\ 
     -I../evolutionaryStuff/include\ 
     -I../geom/include\ 
     -I../model/include\ 
     -I../paramsReader/include\ 
     -I../ctrnn/include\ 
     -I../simulationSystem/include 

    AM_LDFLAGS= @[email protected] \ 
     -install_name "./.libs/libphysics.0.dylib" 

...然而,当我做:

otool -D libphysics.0.dylib

中的.libs目录

我得到

/usr/local/lib/libphysics.0.dylib

(但我希望它像的.libs/libphysics.0.dylib)

我知道它一定是简单的东西,任何想法?

感谢,

本。

黑客左右后,它似乎在Makefile.am文件的正确条目应为:

AM_LDFLAGS= @[email protected]\ 
      -Xlinker -rpath -Xlinker "`pwd`/.libs"\ 
      -Xlinker -install_name -Xlinker "`pwd`/.libs/libphsyics.0.dylib" 

我不知道为什么这个工程。窍门是在'-rpath'和'-install_name'之前和之后添加'-Xlinker'标志对。如果有人能告诉我为什么这是必要的,我会很感激。

谢谢,

本。

编辑:我应该指出,这个帖子How to set the runtime path (-rpath) of an executable with gcc under Mac OSX?有助于解决这个问题。