[cfe-users] Using llvm-ar & llvm-ranlib vs ar & ranlib for creating static libraries when thinLTO is enabled.
Mateusz Zych via cfe-users
cfe-users at lists.llvm.org
Thu Aug 9 03:05:41 PDT 2018
Hi :)
I am trying to compile simple project consisting of an executable "app" and
static library "bar".
Note that I'm enabling thinLTO for both "app" and "bar".
////////////////////////////////////////
// bar.h //
////////////////////////////////////////
#ifndef BAR
#define BAR
void bar ();
#endif
////////////////////////////////////////
////////////////////////////////////////
// bar.cpp //
////////////////////////////////////////
#include "bar.h"
#include <iostream>
void bar ()
{
std::cout << "Bar" << std::endl;
}
////////////////////////////////////////
////////////////////////////////////////
// app.cpp //
////////////////////////////////////////
#include "bar.h"
#include <iostream>
int main()
{
std::cout << "App" << std::endl;
bar();
}
////////////////////////////////////////
When I'm using llvm-ar and llvm-ranlib to create static library everything
works fine:
$ clang++ -flto=thin -c bar.cpp -o bar.o
$ llvm-ar cr bar.a bar.o
$ llvm-ranlib bar.a
$ clang++ -flto=thin -c app.cpp -o app.o
$ clang++ -flto=thin -o app app.o bar.a
However using default ar and ranlib provided by my GNU/Linux distribution
results in linking failure:
$ clang++ -flto=thin -c bar.cpp -o bar.o
$ ar cr bar.a bar.o
$ ranlib bar.a
$ clang++ -flto=thin -c app.cpp -o app.o
$ clang++ -flto=thin -o app app.o bar.a
bar.a: *error adding symbols: Archive has no index; run ranlib to add one*
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Note that for GCC using default ar and ranlib works fine:
$ g++ -flto -c bar.cpp -o bar.o
$ ar cr bar.a bar.o
$ ranlib bar.a
$ g++ -flto -c app.cpp -o app.o
$ g++ -flto -o app app.o bar.a
Obviously using gcc-ar and gcc-ranlib also works fine:
$ g++ -flto -c bar.cpp -o bar.o
$ gcc-ar cr bar.a bar.o
$ gcc-ranlib bar.a
$ g++ -flto -c app.cpp -o app.o
$ g++ -flto -o app app.o bar.a
My question is: *Can I use ar and ranlib provided by GNU/Linux with
clang++?*
If not, then to properly setup clang as a default compiler on GNU/Linux
machine,
I should not only run update-alternatives for cc and c++ commands,
but also somehow do that for ar and ranlib commands?
$ sudo update-alternatives --config cc
$ sudo update-alternatives --config c++
That's very problematic since update-alternatives doesn't work with ar and
ranlib:
$ sudo update-alternatives --config ar
update-alternatives: error: no alternatives for ar
$ sudo update-alternatives --config ranlib
update-alternatives: error: no alternatives for ranlib
If default ar and ranlib is expected to not work with clang++,
then how should I setup Clang as a default compiler on GNU/Linux?
Thanks, Mateusz Zych
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20180809/3e6ffebf/attachment.html>
More information about the cfe-users
mailing list