title: Order of objects in a static library
body: <p>I have a C project using several object files that needs to be linked in a specific order to find all needed symbols.</p>
  
  <p>For example this command works fine (lib2.o depends on lib1.o etc.)</p>
  
  <pre><code>gcc -o my_app main.o lib1.o lib2.o lib3.o -lm
  </code></pre>
  
  <p>but </p>
  
  <pre><code>gcc -o my_app main.o lib3.o lib2.o lib1.o -lm
  </code></pre>
  
  <p>ends with undefined reference to `my_variable' errors.</p>
  
  <p>This is a known behavior and can be solved for example by adding these objects to GROUP section in a linker script.</p>
  
  <p>Now I'd like to share these object as a static library with my colleagues. So...</p>
  
  <pre><code>ar -rcs mylib.a lib1.o lib2.o lib3.o
  gcc -o my_app main.o mylib.a -lm
  </code></pre>
  
  <p>Unfortunately this gives the same undefined reference errors like the specifying the objects in incorrect order. </p>
  
  <p>I have not found any linker or archiver options to make it working and also no solution by googling even if I think that this problem should be relatively common.</p>
  
  <p>Do please anybody know a solution?</p>
  
  <p>regards
  Jan</p>