Issue with GMP static linkage (and bundle)

atlantis23 vk at
Mon Oct 2 13:05:40 UTC 2017

> Am 22.09.2017 um 21:19 schrieb Daniele Ghisi <danieleghisi at>:
> Dear GMP users,
> I need to link GMP statically to a project (written in C).
> I can't seem to do it if the Mach-O Type of my target is set to "Bundle".
> No issues when it is set to "executable" or "static library".
> No issues when I use dynamic linkage either (with -lgmp)
> I am on OS X 10.10.5, Xcode 7.2
> I have tried to install GMP manually or with homebrew, in both cases I
> still get the issue.
> The specific error is
> "ld: illegal text-relocation to '___gmp_binvert_limb_table' in
> /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in
> /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see invocation)"

I don't get this error on my Mac (10.11.6, Xcode 7.3.1).
My test project is a System plug-in which links against a static libgmp.a (a homebrew built).
The project builds and works as expected.

I'm not a Mach-O expert, but your error message looks like your linker tries to relocate symbols (when linking the static gmp).

The header of my Mach-O executable looks like
otool -hv ...
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  X86_64        ALL  0x00      BUNDLE    19       2712   NOUNDEFS DYLDLINK TWOLEVEL

The code actually links to libgmp, for example
otool -tV ...
(__TEXT,__text) section
00000000000019b5	callq	0x1d50                  ## symbol stub for: ___gmpn_divexact_1

However, there is no relocation table,
otool -r
returns empty.

Are you sure you're using the correct gmp.h version for the linked libgmp.a? The error message refers to symbol
which is used in gmp 6.1.2 but was not present in older versions.


More information about the gmp-discuss mailing list