How do I force the linker to use a function from a defined library?

The case may occur in a software project where functions with identical names exist in different libraries. A symbol is created for each function; thus for functions with identical names, there will be several symbols of the same name. Using one of these functions will cause a linker error due to the conflict of symbols. To avoid this situation, follow these steps:

  1. Add the linker option -u <symbol> or --undefined=<symbol> (replace <symbol> with the name of the function).

  2. The library including the function you wish to use must be the first to be passed to the linker.

Due to the option -u <symbol> the symbol is undefined, this forces the linker to resolve the reference by taking the first matching symbol it encounters in the library.