【发布时间】:2011-11-02 10:05:38
【问题描述】:
我正在为 Mac OS X (10.7.1) 上的 C++ 构建 google-gflags 命令行标志库。构建过程是这样的:
$ ./configure --prefix=output
$ make
$ make install
我想在构建时更改生成的共享库的安装名称,之后不再使用install_name_tool。
默认情况下,生成的共享库libgflags.dylib的install 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
那么,我是否可以在不使用install_name_tool 的情况下更改configure 和make 生成的.dylib 的安装名称?
【问题讨论】:
-
我不明白你在做什么。为什么不能简单地运行
./configure --prefix /tmp/desired/location? -
这是一个有效的问题。由于各种原因,我无法将
--prefix设置为该位置,包括我的构建位置与我的应用程序的“安装”位置不同。我只是想在使用configure时传递适当的链接器标志。 -
你的场景我还不清楚。您能否解释一下标准
./configure --prefix /somewhere && make && make install对您的设置有何错误?为什么您的构建位置很重要? (当然,您应该使用绝对前缀。)您是否尝试链接到libglflags而不安装它? (在这种情况下,您应该使用libtool将您的应用程序与libflag.la链接起来,并让 libtool 发挥它的魔力来链接未安装的库。)您想在将库复制到之前将其安装到临时位置吗?它的最终位置? (这是 DESTDIR 变量的工作。) -
苹果人推荐使用
-headerpad_max_install_names来编译和链接。然后,当您make install时,您使用install_name_tool更新记录,使其指向完全限定的路径名(即/usr/local/lib/libfoo.dylib)。 Nick X 的回答基本相同,只是没有提到苹果的推荐或-headerpad_max_install_names。
标签: macos shared-libraries autoconf install-name-tool