我正在构建适用于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)
的man页面有一个-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
? - adl--prefix
设置为该位置,因此我无法这样做。我只想在使用configure
时传递适当的链接器标志。 - v8891./configure --prefix /somewhere && make && make install
在您的设置中是错误的呢?为什么构建位置很重要?(当然,您应该使用绝对前缀。)您是否试图在未安装libglflags
的情况下链接到它?(在这种情况下,您应该使用libtool
将您的应用程序与libflag.la
链接,并让libtool
利用其魔力链接到一个未安装的库。)您想在将库复制到最终位置之前将库安装到临时位置吗?(这是DESTDIR变量的工作。) - adl-headerpad_max_install_names
进行编译和链接。然后,当您使用make install
时,使用install_name_tool
更新记录,使其指向完全限定的路径名(即/usr/local/lib/libfoo.dylib
)。Nick X基本上回答了相同的问题,但他没有提到苹果公司的建议或-headerpad_max_install_names
***。 - jww