-h和 -h之间的区别和 -o<输出文件>抄送 (C++) 中的选项输出文件>
我正在构建 .so 库,想知道 -b/w -h 和 -o cc 编译器选项(使用 Sun Studio C++)有什么区别?
他们不是指的是同一件事 - 输出文件的名称吗?
I am building .so library and was wondering - what is the difference b/w -h and -o cc complier option (using the Sun Studio C++) ?
Aren't they are referring to the same thing - the name of the output file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-o
是将由编译器写入磁盘的文件的名称-h
是将记录在链接到该文件的 ELF 二进制文件中的名称。一种常见用途是提供库次版本号。例如,如果
你正在创建共享库 libfoo,你可以这样做:
然后,如果你编译你的 hello world 应用程序并使用 hello 的 elf 二进制文件链接它,
将为
libfoo.so 记录一个
(您可以NEEDED
条目.1通过运行
elfdump -d hello
查看)。然后当您稍后需要添加新功能时,您可以将
-o
值更改为libfoo.so.1.1
但将 -h 保留在libfoo.so.1
- 您已经构建的所有程序1.0 仍然尝试在运行时加载
libfoo.so.1
,因此可以继续工作而不会被重建,但你会通过 ls 看到它是 1.1。
在同一目录中构建库时有时也会使用此方法
在运行时使用,如果没有单独的安装目录或安装
通过包装系统。为了避免您运行时崩溃的程序
覆盖库二进制文件,并避免程序无法启动
你正在构建中,一些 Makefile 会这样做:(
由 X 的旧 Imake makefile 生成器构建的 Makefile 通常会执行此操作。)
-o
is the name of the file that will be written to disk by the compiler-h
is the name that will be recorded in ELF binaries that link against this file.One common use is to provide library minor version numbers. For instance, if
you're creating the shared library libfoo, you might do:
Then if you compile your hello world app and link against it with
the elf binary for hello will record a
NEEDED
entry forlibfoo.so.1
(which you cansee by running
elfdump -d hello
).Then when you need to add new functions later, you could change the
-o
value tolibfoo.so.1.1
but leave the -h atlibfoo.so.1
- all the programs you already builtwith 1.0 still try to load
libfoo.so.1
at runtime, so continue to work without beingrebuilt, but you'll see via ls that it's 1.1.
This is also sometimes used when building libraries in the same directory they're
used at runtime, if you don't have a separate installation directory or install
via a packaging system. To avoid crashing programs that are running when you
overwrite the library binary, and to avoid programs not being able to start when
you're in the middle of building, some Makefiles will do:
(Makefiles built by the old Imake makefile generator from X commonly do this.)
他们指的是不同的名字。具体来说,
-o
选项是文件的实际名称 - 文件系统上的名称。-h
选项设置最终目标文件中的内部DT_SONAME
。这是其他模块在内部引用共享对象的名称。我相信当您在链接到它的对象上运行 ldd 时,您也会看到这个名称。They are referring to different names. Specifically, the
-o
option is the file's actual name - the one on the filesystem. The-h
option sets the internalDT_SONAME
in the final object file. This is the name by which the shared object is referenced internally by other modules. I believe it's the name that you also see when you runldd
on objects that link to it.-o 选项将为输出文件命名,而 -h 选项将在库内设置内部名称。当动态加载器使用时,此内在名称优先于文件名,并允许它使用预定义的规则来查看正确的库。
您可以使用该命令查看给定库中记录的内部名称:
elfdump -d xxx.so | grep SONAME
查看此处了解详细信息:
http:// /docs.oracle.com/cd/E23824_01/html/819-0690/chapter4-97194.html
The -o option will name the output file while the -h option will set an intrinsic name inside the library. This intrinsic name has precedence over the file name when used by the dynamic loader and allows it to use predefined rules to peek the right library.
You can see what intrinsic name was recorded into a given library with that command:
elfdump -d xxx.so | grep SONAME
Have a look here for details:
http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter4-97194.html