homebrewbfd

How to link with libbfd on MacOS?


I'm trying to build with libbfd on MacOS. I haven't found anything that indicates that Apple Clang would provide anything similar so I'm "stuck" on Homebrew.

Linking with /usr/local/opt/binutils/lib/libbfd.a I get a lot of unresolved symbols, some detective work showed that some at least came from libiberty so thanks to https://stackoverflow.com/a/65978315/204658 I resolved most of them, but I still have a few which are also a bit confusing:

Undefined symbols for architecture x86_64:
  "_compress", referenced from:
      _bfd_compress_section_contents in libbfd.a(compress.o)
     (maybe you meant: __bfd_pex64_print_ce_compressed_pdata, __bfd_pep_print_ce_compressed_pdata , _bfd_init_section_compress_status , _bfd_is_section_compressed , _bfd_is_section_compressed_with_header , __bfd_pe_print_ce_compressed_pdata , _bfd_compress_section , _bfd_get_compression_header_size , _bfd_update_compression_header , _bfd_check_compression_header )
  "_compressBound", referenced from:
      _bfd_compress_section_contents in libbfd.a(compress.o)
  "_inflate", referenced from:
      _decompress_contents in libbfd.a(compress.o)
  "_inflateEnd", referenced from:
      _decompress_contents in libbfd.a(compress.o)
  "_inflateInit_", referenced from:
      _decompress_contents in libbfd.a(compress.o)
  "_inflateReset", referenced from:
      _decompress_contents in libbfd.a(compress.o)

Solution

  • Those symbols are from the libz library.

    On many platforms you don't need to explicitly link with libz, but on Homebrew you do.

    You need to link using -libz.