Skip to content

configure: don't use -flat_namespace on Darwin

In modern versions of macOS, libraries and binaries default to a two-level namespace where symbols are located by their name as well as the library in which the symbol can be found. It's possible to tell the linker to use a flat (single-level) namespace instead (a la ELF in Linux) by passing -flat_namespace -undefined <option> in LDFLAGS (-undefined <option> instructs the desired behavior to follow when a symbol is not found in the flat namespace), but unless the program being built specifically needs the benefits/configuration of a flat namespace, explicitly passing these options is unnecessary.

Flat namespaces allow for a binary foo to look for a symbol bar and find it in libbar, but the user could also provide an alternative implementation of symbol bar in libbaz and foo would link to it without complaints. In a two-level namespaces, this kind of symbol "hot-plug" is not possible.

If the above scenario is not applicable, then it's probably better to use a two-level namespace. Flat namespaces can cause errors at symbol binding time, and (in that support thread) Apple staff even notes that "the flat namespace is effectively deprecated and we encourage folks not to use it".

Merge request reports

Loading