v88*_*891 7 macos autoconf shared-libraries install-name-tool
我正在为Mac OS X(10.7.1)上的C++ 构建google-gflags命令行标记库.构建过程如下:
$ ./configure --prefix=output
$ make
$ make install
Run Code Online (Sandbox Code Playgroud)
我想在构建时更改生成的共享库的安装名称,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)
Run Code Online (Sandbox Code Playgroud)
手册页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)
Run Code Online (Sandbox Code Playgroud)
但是,我无法在./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
Run Code Online (Sandbox Code Playgroud)
那么,我是否可以更改使用configure
和make
不使用生成的.dylib的安装名称install_name_tool
?
通常,通过g ++传递链接器参数必须以-Wl开头,并且空格必须用逗号替换.因此,如果要将"-install_name /tmp/temp.dylib"传递给链接器,则需要调用此方法:
g++ -Wl,-install_name,/tmp/temp.dylib ...
Run Code Online (Sandbox Code Playgroud)
one possible approach would be editing the config.status manually. but before I try to do that, install_name_tool -id
saved my life.
归档时间: |
|
查看次数: |
7747 次 |
最近记录: |