title: Using GCC's link-time optimization with static linked libraries
body: <p>I'm trying to use link-time optimizations with the <code>-flto</code> flag of GCC (6.1.1).</p>
  
  <p>While it works fine with my code, it doesn't link with a static linked library I'm also building and linking with my project (which is <a href="https://github.com/cpcdoy/Engine" rel="noreferrer">Engine</a> and the library is <a href="https://github.com/aras-p/glsl-optimizer" rel="noreferrer">glsl-optimizer</a>, just for reference).</p>
  
  <p>Here is the output:</p>
  
  <pre><code>...
  /usr/bin/ranlib: ir_expression_flattening.cpp.o: plugin needed to handle lto object
  /usr/bin/ranlib: opt_function_inlining.cpp.o: plugin needed to handle lto object
  /usr/bin/ranlib: opt_copy_propagation_elements.cpp.o: plugin needed to handle lto object
  ...
  </code></pre>
  
  <p>And after that, of course, I get several "undefined references" to some functions.</p>
  
  <p>I did some research and found out that it might be because of <code>ar</code>, and I should try to use <code>gcc-ar</code>, but I'm not sure how I might do that.</p>
  
  <p>Also, I'm using CMake that does not support lto (except on Intel's compiler on some platforms, so I read...). Even though, I tried using:</p>
  
  <pre><code>set_property(TARGET glsl_optimizer PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
  </code></pre>
  
  <p>Which didn't work.</p>
  
  <p>Also, I tried GCC's <code>-fuse-linker-plugin</code> flag which didn't work.</p>
  
  <p>I guess I'll have to do it manually the old way directly using <code>gcc-ar</code>, or maybe there's some other method?</p>