如何在构建时修改 .dylib 的安装名称

发布于 2024-12-01 05:43:40 字数 1980 浏览 5 评论 0原文

我正在 Mac OS X (10.7 .1).构建过程如下:

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

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

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

$ 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

那么,我是否可以更改由 configure 生成的 .dylib 的安装名称并make而不使用install_name_tool

I am building the google-gflags commandline flags library for C++ on Mac OS X (10.7.1). The build process is as such:

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

I'd like to change the install name of the generated shared library at build time and not use install_name_tool afterwards.

By default, the install name of the generated shared library, libgflags.dylib, is the output path:

$ 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) 

The man page for ld(1) has a -install_name option which can be used to change the install name of a dynamic library at link-time.

For example, with a dummy program:

$ 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)

But, I am unable to use this command line option with the ./configure script. I've tried manually setting the CFLAGS variable, but that results in a error:

$ 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

So, is it possible for me to change the install name of .dylib generated by configure and make without using install_name_tool?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生活了然无味 2024-12-08 05:43:40

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

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

Generally, passing linker arguments through g++ must be prefaced with -Wl and spaces must be replaced with commas. So, if you want to pass "-install_name /tmp/temp.dylib" to the linker you will need to call this:

g++ -Wl,-install_name,/tmp/temp.dylib ...
心的憧憬 2024-12-08 05:43:40

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

one possible approach would be editing the config.status manually. but before I try to do that, install_name_tool -id saved my life.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文