dieharder compilation failure on Apple Silicon: 'ld: symbol(s) not found for architecture arm64'

Attempting to compile dieharder from source on an M1 Max MacBookPro18,2 (macOS 12 + Xcode 13.3.1 + command line tools) and running into an error:

...
/bin/sh ../libtool --tag=CC   --mode=link gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/local/include  -L/opt/local/lib -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o ../libdieharder/libdieharder.la -lgsl -lgslcblas -lm -lgsl -lgslcblas
libtool: link: gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/local/include -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o  -L/opt/local/lib ../libdieharder/.libs/libdieharder.a -lm -lgsl -lgslcblas
Undefined symbols for architecture arm64:
  "_insert", referenced from:
      _dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
      _main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
  "_insertBit", referenced from:
      _dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...

I got to this failure with a MacPorts installed gsl and by executing the following:

$ mkdir dieharder; cd dieharder
$ wget --no-check-certificate https://webhome.phy.duke.edu/~rgb/General/dieharder/dieharder-3.31.1.tgz
$ tar xf dieharder-3.31.1.tgz
$ cd dieharder-3.31.1
$ sudo port install gsl
$ ./configure LDFLAGS=-L/opt/local/lib CPPFLAGS=-I/opt/local/include CFLAGS=-I/opt/local/include --disable-shared
...
$ make
...

I reproduced the failure with Homebrew:

$ brew install gsl
$ make distclean
$ ./configure LDFLAGS=-L/opt/homebrew/lib CPPFLAGS=-I/opt/homebrew/include CFLAGS=-I/opt/homebrew/include --disable-shared
...
$ make
...
/bin/sh ../libtool --tag=CC   --mode=link gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/homebrew/include  -L/opt/homebrew/lib -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o ../libdieharder/libdieharder.la -lgsl -lgslcblas -lm -lgsl -lgslcblas
libtool: link: gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/homebrew/include -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o  -L/opt/homebrew/lib ../libdieharder/.libs/libdieharder.a -lm -lgsl -lgslcblas
Undefined symbols for architecture arm64:
  "_insert", referenced from:
      _dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
      _main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
  "_insertBit", referenced from:
      _dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [dieharder] Error 1
make: *** [dieharder.time] Error 2

Anyone know what might be going on here and how to properly configure this to complete compilation on and for Apple Silicon systems?

Answered by MobileTen in 711330022

The insert functions are not exported public for the ARM compilation of the library.

Undefined symbols for architecture arm64:
  "_insert", referenced from:
      _dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
      _main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
  "_insertBit", referenced from:
      _dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
ld: symbol(s) not found for architecture arm64

Known issue: https://github.com/eddelbuettel/dieharder/pull/1 You will have to fix the issue locally before building.

Accepted Answer

The insert functions are not exported public for the ARM compilation of the library.

Undefined symbols for architecture arm64:
  "_insert", referenced from:
      _dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
      _main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
  "_insertBit", referenced from:
      _dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
ld: symbol(s) not found for architecture arm64

Known issue: https://github.com/eddelbuettel/dieharder/pull/1 You will have to fix the issue locally before building.

dieharder compilation failure on Apple Silicon: 'ld: symbol(s) not found for architecture arm64'
 
 
Q