16

Which linker do I use for Clang?

If I use Clang or GNU linker (ld) as the linker, I get massive amounts of errors as if I didn't link with the standard library.

g++ $(OBJS) -o $(BINDIR)/obtap

It seems I have to use g++ in order to link my Clang objects.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jookia
  • 6,544
  • 13
  • 50
  • 60

3 Answers3

26

I was running 'clang' instead of 'clang++', meaning it didn't link the C++ standard library.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jookia
  • 6,544
  • 13
  • 50
  • 60
4

Follow-up: it's now 2016, and LLVM has made some steady progress on their own linker. It's called "lld", and the website is here. It works fine to create i386 and x86_64 binaries, while work is ongoing to target other systems.

This should remove the dependency on GNU tools for BSD systems, once it is considered stable enough.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Greg Kennedy
  • 430
  • 4
  • 23
4

You do not have to use llvm's link editor. I will avoid getting into the technical details, but, in short, you will need to have a typical Unix link editor available to use Clang at this time (read: GNU ld or Sun ld). Even llvm-ld uses the underlying platform's linker to link native binaries.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wash
  • 497
  • 4
  • 7