2011-08-24 32 views
7

我正在为Mac OS X(10.7.1)上的C++构建google-gflags命令行标志库。构建过程是这样:如何在构建时修改.dylib的安装名称

$ ./configure --prefix=output 
$ make 
$ make install 

我想在构建时改变产生的共享库的安装名称,而不是使用install_name_tool之后。

默认情况下,生成的共享库,libgflags.dylibinstall name,是输出路径:

$ otool -L ./output/libgflags.dylib 
$ ./output/libgflags.dylib: 
    /tmp/gflags-1.5/output/lib/libgflags.0.dylib (compatibility version 2.0.0, current version 2.0.0) 
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0) 
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0) 

ld(1)手册页有一个-install_name选项,它可以用来更改安装一个动态的名字图书馆在链接时。

例如,虚拟程序:

$ g++ -dynamiclib temp.cc -install_name /tmp/temp.dylib -o temp.dylib 
$ otool -L temp.dylib 
temp.dylib: 
    /tmp/temp.dylib (compatibility version 0.0.0, current version 0.0.0) 
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0) 
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0) 

但是,我无法使用与./configure脚本此命令行选项。我已经试过手动设置CFLAGS变量,但导致一个错误:

$ CFLAGS="-install_name /tmp/desired/location/libgflags.dylib" ./configure 
checking for a BSD-compatible install... /opt/local/bin/ginstall -c 
checking whether build environment is sane... yes 
checking for gawk... no 
checking for mawk... no 
checking for nawk... no 
checking for awk... awk 
checking whether make sets $(MAKE)... yes 
checking for gcc... gcc 
checking whether the C compiler works... no 
configure: error: in `/Users/vibhav/Code/install_name_test/gflags-1.5': 
configure: error: C compiler cannot create executables 

那么,是不是我能够改变由configuremake生成名为.dylib的安装名称,而不使用install_name_tool

+0

我不明白你在做什么。为什么不能简单地运行'./configure --prefix/tmp/desired/location'? – adl

+0

这是一个有效的问题。我不能将'--prefix'设置为该位置出于各种原因,包括我的构建位置与我的应用程序的“安装”位置不同。我只是想在使用configure时传递适当的链接器标志。 – v8891

+0

你的情况对我来说还不清楚。你能否解释标准的'./configure --prefix/somewhere && make && make install'对于你的设置是错误的?为什么你的构建位置很重要? (当然,您应该使用绝对前缀。)您是否尝试链接到'libglflags'而不安装它? (在这种情况下,您应该使用'libtool'将您的应用程序与'libflag.la'链接起来,并让libtool发挥它的魔力,以便与未安装的库链接。)是否要在安装库之前将它安装到临时位置复制到其最终位置? (这是DESTDIR变量的一项工作。) – adl

回答

5

通常,通过g ++传递链接器参数必须以-Wl开头,空格必须用逗号替换。所以,如果你想“-install_name /tmp/temp.dylib”传给连接,你需要调用这个:

g++ -Wl,-install_name,/tmp/temp.dylib ... 
4

一个可行的方法是手动编辑config.status。但在我尝试那样做之前,install_name_tool -id拯救了我的生命。

相关问题