title: Incremental linking using gcc on linux. Is it possible?
body: <p>The way my team's project is developed, we generate a Shared Object library for our application from all all of our <code>.o</code> 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:</p>
  
  <pre><code>g++34 -shared -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject2.o MyObject3.o MyObject4.o   -o libMySharedLibrary.so
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>g++34 -shared -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject3.o   -o libMySharedLibrary.so
  </code></pre>
  
  <p>Which would update <code>libMySharedLibrary.so</code> with the newer object files, while maintaining the older object files in <code>libMySharedLibrary.so</code> also. In actuality, when I generate <code>libMySharedLibrary.so</code> 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.</p>
  
  <p>Through my research I've found that there is a <code>-i</code> option for the linker which is the same as the <code>-r</code> 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.</p>
  
  <p>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? </p>
  
  <p>EDIT: An example of what I've tried with <code>-i/-r</code>:</p>
  
  <p>Example command: <code>g++34 -Wl,-r -nostdlib -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject2.o MyObject3.o MyObject4.o  -o AllMyObjects.o</code></p>
  
  <p>I had to add the <code>-nostdlib</code> tag to stop it from yelling at me about needing it, and removed <code>-shared</code> because shared objects are not allowed with the <code>-r</code> tag. </p>
  
  <p>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: <code>g++34 -Wl,-r -nostdlib -rdynamic -m64 -Wl,-rpath,'$ORIGIN' MyObject1.o MyObject3.o  -o AllMyObjects.o</code>, but it would also create a much smaller (file-size-wise) <code>AllMyObjects.o</code>, 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.</p>