11

I am trying to build a project on Mac OS X using clang and it fails on linking step with ld: unknown option: --no-undefined, which is meant to built with gcc. What's the clang equivalent for this option? (Please, don't advise to use gcc instead of clang.)

Also, a more generic question, is there any resource where one can find some kind of a "mapping" between gcc and clang (linker) options differences?

Thank you.

iurii
  • 2,597
  • 22
  • 25
  • 2
    That's a linker option. Use `-Wl,...` and read the doc of your linker (`ld`). With gcc, you can add `-v` to see what option it actually passes to the linker. – Marc Glisse Nov 17 '14 at 12:30

1 Answers1

16

OS X uses a different linker. As @rubenvb points out, it's probably the one from Apple's binutils. If you run man ld, and search for "undefined", you will find this option:

-undefined treatment Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup. The default is error.

So, replace -Wl,--no-undefined with -Wl,-undefined,error. Also, use the Force, Luke.

Pradhan
  • 16,391
  • 3
  • 44
  • 59
  • Are you sure OS X uses LLVM's `lld` and not [Apple's binutils](http://www.opensource.apple.com/source/cctools/)? – rubenvb Nov 18 '14 at 09:03
  • @rubenvb You are more likely to be right than my "educated" guess :) `ld -v` says that it uses LLVM3.5 for LTO. I read more into it than I should have. Removing that part from the answer. If you don't mind, please edit it with the right information. – Pradhan Nov 18 '14 at 09:08
  • Your answer is fine the way it is currently, but for completeness a link to [the status section on the lld website](http://lld.llvm.org/#current-status). – rubenvb Nov 18 '14 at 09:15
  • 1
    Thanks for the tip, @Pradhan. My bad, didn't think of looking into ld man. It worked with one correction: had to use `-Wl,-undefined,error` - otherwise it fails with `clang: error: no such file or directory: 'error'`. – iurii Nov 18 '14 at 09:33