ctypes.sh: Can't build on macOS

Hello, I’m having issues trying to build on macOS.

I use the latest version of bash (not the outdated version macOS comes with, so it should support bash plugins)

$ bash --version
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0)

Running ./configure gives me

configure: WARNING: elfutils is not available, struct support will not be available
[...]
checking whether bash symbols are exported... no
configure: error: in `~/code/ctypes.sh':
configure: error: unable to build a test extension
See `config.log' for more details

In config.log I see

configure:13864: checking whether bash symbols are exported
configure:13891: gcc -o conftest -g -O2  -I./include  -shared -fPIC conftest.c -lelf  >&5
Undefined symbols for architecture x86_64:
  "_num_shell_builtins", referenced from:
      _conftest_function in conftest-efa94e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:13891: $? = 1
configure: failed program was:
| /* confdefs.h */
[...]
|     #include "builtins.h"
| 
|     int conftest_function(WORD_LIST *list)
|     {
|         exit(num_shell_builtins
|                 ? EXIT_SUCCESS
|                 : EXIT_FAILURE);
|     }
| 
|     struct builtin conftest_struct = {
|         .name       = "conftest",
|         .function   = conftest_function,
|         .flags      = BUILTIN_ENABLED,
|         .long_doc   = NULL,
|         .short_doc  = NULL,
|         .handle     = NULL,
|     };
[...]
configure:13911: result: no
configure:13913: error: in `~/code/ctypes.sh':
configure:13915: error: unable to build a test extension
See `config.log' for more details

I don’t know if this has something to do with include/builtins.h since that what defines the extern of num_shell_builtins. The only other thing I can think of is not having struct support since I don’t have elfutils installed (I don’t think it builds for macOS), and the code it tries to compile has a struct. I might be barking up the wrong tree though; I don’t know how to resolve this myself.

Thank you for your time.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

@cemeyer Just to clarify this also compiles successfully.

$ gcc -fPIC -shared -Wl,-undefined,dynamic_lookup -o test test.c

@cemeyer Unfortunately --allow-shlib-undefined doesn’t work for me; I think for clang the equivalent flag is -undefined dynamic_lookup which I was setting in my LDFLAGS above.

I tried setting LD_LIBRARY_PATH and calling bash again before sourcing ctypes.sh but I get the same error as before.

I’m not that familiar with building C on macOS so we’re both guessing in the dark 😃

Thank you so much @cemeyer, that’s very helpful. I have just rebuilt my bash from source with the --enable-disabled-builtins flag; before I didn’t have any such num_shell_builtins symbol but now I do (with a leading underscore)

$ nm -D $(which bash) | grep num_shell
00000001000bde98 D _num_shell_builtins