The way my team's project is developed, we generate a Shared Object library for our application from all all of our .o
object files. My task (hopefully it is specific enough but also general enough to be of use to others!) is to link in only the object files that have changed since the last time the executable was created. For example, here is the command line that i use to build the .so:
根据开发团队项目的方式,我们从所有.o对象文件为应用程序生成一个共享对象库。我的任务(希望它足够具体,但也足够通用,可以用于其他的任务!)是只链接自上次创建可执行文件以来已经更改的对象文件。例如,这是我用来构建。so:
g++34 -shared -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject2.o MyObject3.o MyObject4.o -o libMySharedLibrary.so
Which works as expected! :) My goal is to be able to link in only the changed object files from now on, to speed up the concurrent linking process. An example command would be:
像预期的那样工作!:)我的目标是从现在开始只能链接已更改的对象文件,以加快并发链接进程。一个示例命令是:
g++34 -shared -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject3.o -o libMySharedLibrary.so
Which would update libMySharedLibrary.so
with the newer object files, while maintaining the older object files in libMySharedLibrary.so
also. In actuality, when I generate libMySharedLibrary.so
using the above command, the file-size is much smaller than that of when all object files are included, so I can almost be sure that the above command isn't doing what I want.
这将更新libMySharedLibrary。因此,在libMySharedLibrary中维护旧的对象文件时使用更新的对象文件。所以也。实际上,当我生成libMySharedLibrary时。因此,使用上面的命令,文件大小要比包含所有对象文件时的文件大小小得多,因此我几乎可以确定上面的命令没有执行我想要的操作。
Through my research I've found that there is a -i
option for the linker which is the same as the -r
option, which appears to just combine all the object files into one large object file as well. Unfortunately it does not appear that this is what I want.
通过我的研究,我发现链接器有一个-i选项,它与-r选项相同,它似乎只是将所有的对象文件合并到一个大的对象文件中。不幸的是,这似乎并不是我想要的。
In short, I'd like to link in only the changed object files after the initial link, resulting in quicker linking process for the future links. Is there a way to do this?
简而言之,我只希望在初始链接之后链接已更改的对象文件,从而为将来的链接带来更快的链接过程。有办法吗?
EDIT: An example of what I've tried with -i/-r
:
编辑:我用-i/-r尝试过的一个例子:
Example command: g++34 -Wl,-r -nostdlib -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject2.o MyObject3.o MyObject4.o -o AllMyObjects.o
示例命令:g+ 34 -Wl,-r - notlib -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1。o MyObject2。o MyObject3。o MyObject4。o - o AllMyObjects.o
I had to add the -nostdlib
tag to stop it from yelling at me about needing it, and removed -shared
because shared objects are not allowed with the -r
tag.
我必须添加- notlib标记以阻止它对我使用它的要求,并删除-shared,因为-r标记不允许共享对象。
This command would appear to slam all of my .o files into one big .o file. So If I could just update that .o file from here on out with only the changed .o files, that would be great. After AllMyObjects.o was initially created, I tried this command: g++34 -Wl,-r -nostdlib -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject3.o -o AllMyObjects.o
, but it would also create a much smaller (file-size-wise) AllMyObjects.o
, so I'm assuming it can't possibly have all of the object files. I feel like this is something that I'm likely making a small mistake on. Anyone have any advice? Thanks in advance.
这个命令会将我所有的.o文件压缩到一个大的.o文件中。所以如果我能从这里更新。o文件只用修改过的。o文件,那就太棒了。AllMyObjects之后。o是最初创建的,我尝试了以下命令:g+ 34 -Wl,-r - notlib -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1。o MyObject3。o - o AllMyObjects。o,但是它也会创建一个更小(文件大小)的allmyobject。我假设它不可能包含所有的对象文件。我觉得这是我可能犯的一个小错误。有人有什么建议吗?提前谢谢。
2 个解决方案
#1
6
It looks like you're right about -shared
and -r
not working together. I was skeptical about your old GCC version, but even on Ubuntu 10.10 I can see the same:
看起来你在分享和不合作上是对的。我对你以前的GCC版本持怀疑态度,但即使是在Ubuntu 10.10上,我也能看到同样的情况:
$ ld -shared -r
/usr/bin/ld.bfd.real: -r and -shared may not be used together
Unfortunately, that means you've reached a dead-end if you absolutely need shared objects. The binutils linker simply doesn't implement it.
不幸的是,如果您绝对需要共享对象,这意味着您已经到达了死胡同。binutils链接器只是没有实现它。
If static libraries are an option for you, they are simply archives that can easily be manipulated with the ar
utility.
如果静态库是您的选项,那么它们就是可以使用ar实用程序轻松操作的归档文件。
Otherwise, you'll have to look at different linkers or compiler suites. I can't guarantee that you'll find this feature, though, it seems exotic.
否则,您将不得不查看不同的链接器或编译器套件。我不能保证你会发现这个特性,尽管它看起来很奇特。
#2
3
You can sort of get the behavior you're after using archive/static libraries, but the initial link will still take the same amount of time.
您可以获得使用归档/静态库后的行为,但是初始链接仍然需要相同的时间。
Using an archive file:
使用存档文件:
# Initially create the archive
ar r libmylib.a <all object files>
# Create your shared object (re-use this line after libmylib.a is updated)
g++ -shared -rdynamic -m64 -Wl,-rpath,'$ORIGIN' libmylib.a -o libmylib.so
# Update the archive file
ar r libmylib.a updated1.o updated2.o
As I said, it will still take the same amount of time to actually link the .so
as it did before.
就像我说过的,它仍然需要同样的时间来连接。
#1
6
It looks like you're right about -shared
and -r
not working together. I was skeptical about your old GCC version, but even on Ubuntu 10.10 I can see the same:
看起来你在分享和不合作上是对的。我对你以前的GCC版本持怀疑态度,但即使是在Ubuntu 10.10上,我也能看到同样的情况:
$ ld -shared -r
/usr/bin/ld.bfd.real: -r and -shared may not be used together
Unfortunately, that means you've reached a dead-end if you absolutely need shared objects. The binutils linker simply doesn't implement it.
不幸的是,如果您绝对需要共享对象,这意味着您已经到达了死胡同。binutils链接器只是没有实现它。
If static libraries are an option for you, they are simply archives that can easily be manipulated with the ar
utility.
如果静态库是您的选项,那么它们就是可以使用ar实用程序轻松操作的归档文件。
Otherwise, you'll have to look at different linkers or compiler suites. I can't guarantee that you'll find this feature, though, it seems exotic.
否则,您将不得不查看不同的链接器或编译器套件。我不能保证你会发现这个特性,尽管它看起来很奇特。
#2
3
You can sort of get the behavior you're after using archive/static libraries, but the initial link will still take the same amount of time.
您可以获得使用归档/静态库后的行为,但是初始链接仍然需要相同的时间。
Using an archive file:
使用存档文件:
# Initially create the archive
ar r libmylib.a <all object files>
# Create your shared object (re-use this line after libmylib.a is updated)
g++ -shared -rdynamic -m64 -Wl,-rpath,'$ORIGIN' libmylib.a -o libmylib.so
# Update the archive file
ar r libmylib.a updated1.o updated2.o
As I said, it will still take the same amount of time to actually link the .so
as it did before.
就像我说过的,它仍然需要同样的时间来连接。