8

我正在为 Mac OS X (10.7.1) 上的 C++ 构建google-gflags命令行标志库。构建过程是这样的:

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

我想在构建时更改生成的共享库的安装名称,install_name_tool之后不再使用。

默认情况下,生成的共享库的安装名称libgflags.dylib是输出路径:

$ 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

4

2 回答 2

7

通常,通过 g++ 传递链接器参数必须以 -Wl 开头,并且必须用逗号替换空格。因此,如果您想将“-install_name /tmp/temp.dylib”传递给链接器,您需要调用它:

g++ -Wl,-install_name,/tmp/temp.dylib ...
于 2012-08-29T04:37:55.430 回答
5

一种可能的方法是手动编辑 config.status。但在我尝试这样做之前,install_name_tool -id救了我的命。

于 2012-10-30T05:50:56.457 回答