I cannot compile crystal on macOS.
I am trying to build crystal on macOS and am having trouble with the compiler. I installed crystal, llvm, xml, openssl, yml with homebrew. Crystal was built with llvm 5.0.2 but the llvm that comes with homebrew is 6.0.0.
(cafe:~/source_code/open_source/crystal)$ crystal --version
Crystal 0.25.1 (2018-06-29)
LLVM: 5.0.2
Default target: x86_64-apple-macosx
(cafe:~/source_code/open_source/crystal)$ llvm-config --version
6.0.0
(cafe:~/source_code/open_source/crystal)$ llvm-config --ldflags
-L/usr/local/Cellar/llvm/6.0.0/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names
(cafe:~/source_code/open_source/crystal)$ llvm-config --cxxflags
-I/usr/local/Cellar/llvm/6.0.0/include -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
(cafe:~/source_code/open_source/crystal)$ make
Using /usr/local/bin/llvm-config [version=6.0.0]
CRYSTAL_CONFIG_PATH="/Users/jack/source_code/open_source/crystal/src" ./bin/crystal build -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
Undefined symbols for architecture x86_64:
"_LLVMInitializeInstCombine", referenced from:
_*LLVM::PassRegistry#initialize_inst_combine:Nil in L-L-V-M-5858P-assR-egistry.o
ld: symbol(s) not found for architecture x86_64
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/jack/source_code/open_source/crystal/.build/crystal' -rdynamic /Users/jack/source_code/open_source/crystal/src/llvm/ext/llvm_ext.o `/usr/local/bin/llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lgc -lpthread /Users/jack/source_code/open_source/crystal/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`
make: *** [.build/crystal] Error 1
Not sure if it's a solution or a workaround, but doing brew link --force llvm@5 will default the LLVM version to LLVM 5, and should probably work.
It's a bug in LLVM 6, see https://github.com/crystal-lang/crystal/pull/6306#issuecomment-402140441
This doens't seem to be fixed with llvm 5.0.2 either:
$ make
Using /usr/local/bin/llvm-config [version=5.0.2]
CRYSTAL_CONFIG_PATH="/Users/<username>/crystal-scripts/crystal/src" ./bin/crystal build -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
Undefined symbols for architecture x86_64:
"llvm::DIBuilder::createCompileUnit(unsigned int, llvm::DIFile*, llvm::StringRef, bool, llvm::StringRef, unsigned int, llvm::StringRef, llvm::DICompileUnit::DebugEmissionKind, unsigned long long, bool, bool, bool)", referenced from:
_LLVMDIBuilderCreateCompileUnit in llvm_ext.o
ld: symbol(s) not found for architecture x86_64
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/<username>/crystal-scripts/crystal/.build/crystal' -rdynamic /Users/<username?/crystal-scripts/crystal/src/llvm/ext/llvm_ext.o `/usr/local/bin/llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lgc -lpthread /Users/<username>/crystal-scripts/crystal/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`
make: *** [.build/crystal] Error 1
Although it is a different error, it's still referencing undefined symbols for the architecture.
you need to make clean after changing LLVM versions.
I force linked llvm@5 and it works. I also updated the wiki for now.
I spent some time last night trying to get crystal to build with llvm 6.0 and was having some trouble. It seems like 6.0 has the symbols but they are just not being found. Is it worth getting crystal to work with llvm?
This also works with llvm --HEAD install with homebrew.
Check that llvm 6.0.1 or greater is used. There were a regression in llvm 6 about missing symbols.
That is what it seems like but is crystal going to support llvm 6.0 or are we just going to skip it?
We can't support unmodified LLVM 6 because it has a regression. 6.0.1 doesn't exist (they released 2 6.0.1 release candidates then gave up??). It needs this patch (go submit a PR to homebrew) or you'll have to use LLVM 5.
Most helpful comment
you need to
make cleanafter changing LLVM versions.