Apple Silicon 上的顽固分子编译失败:'ld: symbol(s) not found for architecture arm64'

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

试图在 M1 Max(macOS 12 + Xcode 13.3.1 + 命令行工具)和 运行 上从源代码编译 dieharder 出现错误:

...
/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)
...

我在安装了 MacPorts gsl 并执行以下命令后遇到了这个故障:

$ 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
...

我用 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

有人知道这里会发生什么以及如何正确配置它以在 Apple Silicon 系统上完成编译吗?

原来insert函数没有导出public用于库的ARM编译:

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)

参见:https://github.com/eddelbuettel/dieharder/pull/1/files

在这四行中添加 staticdieharder 编译正常。

所需更改的屏幕截图: