1This directory contains LLVM bindings for the Go programming language 2(http://golang.org). 3 4Prerequisites 5------------- 6 7* Go 1.2+. 8* CMake (to build LLVM). 9 10Using the bindings 11------------------ 12 13The package path "llvm.org/llvm/bindings/go/llvm" can be used to 14import the latest development version of LLVM from SVN. Paths such as 15"llvm.org/llvm.v36/bindings/go/llvm" refer to released versions of LLVM. 16 17It is recommended to use the "-d" flag with "go get" to download the 18package or a dependency, as an additional step is required to build LLVM 19(see "Building LLVM" below). 20 21Building LLVM 22------------- 23 24The script "build.sh" in this directory can be used to build LLVM and prepare 25it to be used by the bindings. If you receive an error message from "go build" 26like this: 27 28 ./analysis.go:4:84: fatal error: llvm-c/Analysis.h: No such file or directory 29 #include <llvm-c/Analysis.h> // If you are getting an error here read bindings/go/README.txt 30 31or like this: 32 33 ./llvm_dep.go:5: undefined: run_build_sh 34 35it means that LLVM needs to be built or updated by running the script. 36 37 $ $GOPATH/src/llvm.org/llvm/bindings/go/build.sh 38 39Any command line arguments supplied to the script are passed to LLVM's CMake 40build system. A good set of arguments to use during development are: 41 42 $ $GOPATH/src/llvm.org/llvm/bindings/go/build.sh -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD=host -DBUILD_SHARED_LIBS=ON 43 44Note that CMake keeps a cache of build settings so once you have built 45LLVM there is no need to pass these arguments again after updating. 46 47Alternatively, you can build LLVM yourself, but you must then set the 48CGO_CPPFLAGS, CGO_CXXFLAGS and CGO_LDFLAGS environment variables: 49 50 $ export CGO_CPPFLAGS="`/path/to/llvm-build/bin/llvm-config --cppflags`" 51 $ export CGO_CXXFLAGS=-std=c++11 52 $ export CGO_LDFLAGS="`/path/to/llvm-build/bin/llvm-config --ldflags --libs --system-libs all`" 53 $ go build -tags byollvm 54