Pb compiling with the 'static' option on Mac OS

Does it point to a problem with the compiler or to a missing library ?

NB: The same operation works correctly when omitting the ‘static’ option

Alternatively : How do I distribute an app written in Crystal, if it is not statically compiled ?

otool -L ./bin/hello yields:

./bin/hello:
	/opt/homebrew/opt/bdw-gc/lib/libgc.1.dylib (compatibility version 7.0.0, current version 7.1.0)
	/opt/homebrew/opt/libevent/lib/libevent-2.1.7.dylib (compatibility version 8.0.0, current version 8.1.0)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

The problem seems to be related to:

crystal build ./src/hello.cr --static --release --progress
ld: library not found for -lcrt0.o **(this usually means you need to install the development package for libcrt0.o)**

clang: error: linker command failed with exit code 1 (use -v to see invocation)

**Error:** **execution of command failed with code: 1: `cc "${@}" -o /Users/sergehulne/Documents/code/Crystal/0_hello/hello/hello -rdynamic -static -L/opt/homebrew/Cellar/crystal/1.7.2/libexec/../../../../lib -lgc -L/opt/homebrew/Cellar/libevent/2.1.12/lib -levent -liconv`**

If I understand this correctly, I should ship the executable along with libgc.1.dylib and libevent-2.1.7.dylib so that it can be executed on another Mac (using something like: macos - Why is install_name_tool and otool necessary for Mach-O libraries in Mac Os X? - Stack Overflow) ?

You’re probably running into Static Linking - Crystal.

1 Like