<div dir="ltr"><div class="gmail_default"><font face="arial, helvetica, sans-serif">Hi :)</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">I am trying to compile simple project consisting of an executable "app" and static library "bar".</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Note that I'm enabling thinLTO for both "app" and "bar".</font></div><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div><div class="gmail_default"><font face="monospace, monospace" size="1">// bar.h //</font></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">#ifndef BAR</span></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">#define BAR</span></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><br></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">void bar ();</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><br></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">#endif</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1"><br></font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1">// bar.cpp //</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div></div><div class="gmail_default"><div><div><font face="monospace, monospace" size="1">#include "bar.h"</font></div></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1">#include <iostream></font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1"><br></font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1">void bar ()</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1">{</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1"> std::cout << "Bar" << std::endl;</font></div></div><div class="gmail_default"><div><font face="monospace, monospace" size="1">}</font></div></div><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div><div class="gmail_default"><font face="monospace, monospace" size="1"><br></font></div><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div><div class="gmail_default"><font face="monospace, monospace" size="1">// app.cpp //</font></div><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">////////////////////////////////////////</span>
</font></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">#include "bar.h"</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">#include <iostream></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><br></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">int main()</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">{</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="white-space:pre"> </span>std::cout << "App" << std::endl;</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1"><span style="white-space:pre"> </span>bar();</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" size="1">}</font></div></div><div class="gmail_default"><font face="monospace, monospace" size="1">////////////////////////////////////////</font></div></blockquote><div class="gmail_default" style="font-family:"courier new",monospace"><br></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">When I'm using llvm-ar and llvm-ranlib to create static library everything works fine:</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">$ clang++ -flto=thin -c bar.cpp -o bar.o</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">$ <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">llvm-ar cr bar.a bar.o</span></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">$ llvm-ranlib bar.a</span></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">$ <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">clang++ -flto=thin -c app.cpp -o app.o</span></span></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">$ clang++ -flto=thin -o app app.o bar.a</span></span></font></div></div></blockquote><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="arial, helvetica, sans-serif">However using default ar and ranlib provided by my GNU/Linux distribution results in linking failure:</font></span><br></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">$ clang++ -flto=thin -c bar.cpp -o bar.o</font></div></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">$ <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">ar cr bar.a bar.o</span></font></div></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">$ ranlib bar.a</span></font></div></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">$ <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">clang++ -flto=thin -c app.cpp -o app.o</span></span></font></div></font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">$ clang++ -flto=thin -o app app.o bar.a</span></span></font></div><div class="gmail_default" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div class="gmail_default">bar.a: <b>error adding symbols: Archive has no index; run ranlib to add one</b></div><div class="gmail_default">clang: error: linker command failed with exit code 1 (use -v to see invocation)</div></span></span></font></div></font></div></div></blockquote><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">
</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Note that for GCC using default ar and ranlib works fine:</font></div><div class="gmail_default" style="font-family:"courier new",monospace"><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">$ g++ -flto -c bar.cpp -o bar.o</font></div></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">$ </font><span style="font-family:monospace,monospace">ar cr bar.a bar.o</span></div></div><div class="gmail_default"><div class="gmail_default"><span style="font-family:monospace,monospace">$ ranlib bar.a</span></div></div><div class="gmail_default"><div class="gmail_default"><span style="font-family:monospace,monospace">$ g++ -flto -c app.cpp -o app.o</span></div></div><div class="gmail_default"><div class="gmail_default"><span style="font-family:monospace,monospace">$ g++ -flto -o app app.o bar.a</span></div></div></blockquote><div class="gmail_default"><div class="gmail_default"><br></div><div class="gmail_default">Obviously using gcc-ar and gcc-ranlib also works fine:</div><div class="gmail_default"><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><div class="gmail_default"><div class="gmail_default" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">$ g++ -flto -c bar.cpp -o bar.o</font></div></div></div><div class="gmail_default"><div class="gmail_default"><div class="gmail_default" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">$ gcc-</font><span style="font-family:monospace,monospace">ar cr bar.a bar.o</span></div></div></div><div class="gmail_default"><div class="gmail_default"><div class="gmail_default" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace">$ gcc-ranlib bar.a</span></div></div></div><div class="gmail_default"><div class="gmail_default"><div class="gmail_default" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace">$ g++ -flto -c app.cpp -o app.o</span></div></div></div><div class="gmail_default"><div class="gmail_default"><div class="gmail_default" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace">$ g++ -flto -o app app.o bar.a</span></div></div></div></blockquote><div class="gmail_default"><div class="gmail_default"><br></div><div class="gmail_default">My question is: <b>Can I use ar and ranlib provided by GNU/Linux with clang++?</b></div><div class="gmail_default"><br>If not, then to properly setup clang as a default compiler on GNU/Linux machine,</div><div class="gmail_default">I should not only run update-alternatives for cc and c++ commands,<br>but also somehow do that for ar and ranlib commands?</div><div class="gmail_default"><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">$ sudo update-alternatives --config cc</font></div><div class="gmail_default"><span style="font-family:monospace,monospace">$<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> sudo update-alternatives --config c++</span> </span></div></div></blockquote><div class="gmail_default"><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">That's very problematic since update-alternatives doesn't work with ar and ranlib:</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="monospace, monospace">
<blockquote style="text-decoration-style:initial;text-decoration-color:initial;margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small"><font face="monospace, monospace">$ sudo update-alternatives --config ar</font></div><div class="gmail_default"><font face="monospace, monospace">update-alternatives: error: no alternatives for ar<br></font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:small"><span style="font-family:monospace,monospace">$<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> sudo update-alternatives --config ranlib</span></span></div><div class="gmail_default"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">update-alternatives: error: no alternatives for ranlib</span></div></div></blockquote></font></div><div class="gmail_default"><br></div><div class="gmail_default">If default ar and ranlib is expected to not work with clang++,<br>then how should I setup Clang as a default compiler on GNU/Linux?</div><div class="gmail_default"><br></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Thanks, Mateusz Zych</font></div></div></div>