Jump to content

Category talk:Nim

From Rosetta Code

External non-native Nim packages (those not written in Nim) apparently do not link properly on MacOS

Hi;

External non-native Nim packages (those not written in Nim) apparently do not link properly on MacOS.

I obtained my Nim and Nimble from MacPorts.

I chatted with the MacPorts guys about this and they did confirm that they have experienced this as well and are quite convinced that this is not a MacPorts issue.

It looks like there are at least two Nim external libraries that silently fail to link properly when installed on MacOS (either x86-64 or arm64).

One of these libraries is "bignum".

An example:

Hickerson series of almost integers

TL;DR

dlopen(libgmp.dylib, 0x0002): tried: 'libgmp.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibgmp.dylib' (no such file), '/usr/lib/libgmp.dylib' (no such file, not in dyld cache), 'libgmp.dylib' (no such file)
could not load: libgmp.dylib
Hint: used config file '/opt/local/lib/nim/config/nim.cfg' [Conf]
Hint: used config file '/opt/local/lib/nim/config/config.nims' [Conf]
.................................................................................
CC: ../../../../../../../opt/local/lib/nim/lib/std/private/digitsutils.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/assertions.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/formatfloat.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/dollars.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/io.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/parseutils.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/unicode.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/strutils.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/strformat.nim
CC: ../../../../../.nimble/pkgs/gmp-0.2.5/gmp.nim
CC: ../../../../../.nimble/pkgs/bignum-1.0.4/bignum.nim
CC: hickerson_series_of_almost_integers.nim
Hint:  [Link]
ld: warning: ignoring duplicate libraries: '-lm'
Hint: gc: refc; opt: speed; options: -d:release
45525 lines; 0.992s; 60.812MiB peakmem; proj: ./hickerson_series_of_almost_integers.nim; out: ./hickerson_series_of_almost_integers [SuccessX]
could not load: libgmp.dylib
(compile with -d:nimDebugDlOpen for more information)

Here is what happens when I try to install "bignum" via Nimble (I actually uninstalled just prior to installation):

nimble install bignum
Downloading https://github.com/SciNim/bignum using git
  Verifying dependencies for bignum@1.0.4
      Info: Dependency on gmp@>= 0.2.4 already satisfied
  Verifying dependencies for gmp@0.2.5
 Installing bignum@1.0.4
   Success: bignum installed successfully.
nim c ./hickerson_series_of_almost_integers.nim
Hint: used config file '/opt/local/lib/nim/config/nim.cfg' [Conf]
Hint: used config file '/opt/local/lib/nim/config/config.nims' [Conf]
.................................................................................
CC: ../../../../../../../opt/local/lib/nim/lib/std/private/digitsutils.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/assertions.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/formatfloat.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/dollars.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system/io.nim
CC: ../../../../../../../opt/local/lib/nim/lib/system.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/parseutils.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/unicode.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/strutils.nim
CC: ../../../../../../../opt/local/lib/nim/lib/pure/strformat.nim
CC: ../../../../../.nimble/pkgs/gmp-0.2.5/gmp.nim
CC: ../../../../../.nimble/pkgs/bignum-1.0.4/bignum.nim
CC: hickerson_series_of_almost_integers.nim
Hint:  [Link]
ld: warning: ignoring duplicate libraries: '-lm'
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
45525 lines; 0.464s; 60.703MiB peakmem; proj: ./hickerson_series_of_almost_integers.nim; out: ./hickerson_series_of_almost_integers [SuccessX]
file ./hickerson_series_of_almost_integers
./hickerson_series_of_almost_integers: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
./hickerson_series_of_almost_integers
could not load: libgmp.dylib
(compile with -d:nimDebugDlOpen for more information)

Retired Build Engineer (talk)

I have a workaround suggested by the MacPorts mailing list for Nim external package linkage issues experienced on MacOS:

nim --dynlibOverride:gmp --passL:"/opt/local/lib/libgmp.dylib" c ./benfords_law.nim

in place of

nim c ./benfords_law.nim

Retired Build Engineer (talk)

Cookies help us deliver our services. By using our services, you agree to our use of cookies.