go-clang / gen

Generate Go bindings for Clang's C API
https://pkg.go.dev/github.com/go-clang/gen
BSD 3-Clause "New" or "Revised" License
44 stars 5 forks source link

cannot find -lclang #143

Closed gchallen closed 7 years ago

gchallen commented 7 years ago

I'm sure I'm doing something incredibly braindead here, but would still appreciate some help. (I'm on xenial.)

$ sudo apt-get install clang llvm
$ go version
go version go1.7.5 linux/amd64
$ clang -v
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
$ llvm-config --libdir
/usr/lib/llvm-3.8/lib
$ ls -l /usr/lib/llvm-3.8/lib/libclang*
lrwxrwxrwx 1 root root 40 Jul 12  2016 /usr/lib/llvm-3.8/lib/libclang-3.8.so.1 -> ../../x86_64-linux-gnu/libclang-3.8.so.1
lrwxrwxrwx 1 root root 17 Jul 12  2016 /usr/lib/llvm-3.8/lib/libclang.so.1 -> libclang-3.8.so.1
$ ls -l ls -l /usr/lib/llvm-3.8/lib/../../x86_64-linux-gnu/libclang-3.8.so.1
-rw-r--r-- 1 root root 14667400 Jul 12  2016 /usr/lib/llvm-3.8/lib/../../x86_64-linux-gnu/libclang-3.8.so.1
$ CGO_LDFLAGS="-L`llvm-config --libdir`" go get -u github.com/go-clang/v3.8/...
../../../../.gvm/pkgsets/go1.7.5/global/src/github.com/go-clang/v3.8/clang/clang_gen.go: In function ‘_cgo_f7c996090904_Cfunc_clang_getDiagnosticCategoryName’:
../../../../.gvm/pkgsets/go1.7.5/global/src/github.com/go-clang/v3.8/clang/clang_gen.go:252:2: warning: ‘clang_getDiagnosticCategoryName’ is deprecated [-Wdeprecated-declarations]
In file included from ../../../../.gvm/pkgsets/go1.7.5/global/src/github.com/go-clang/v3.8/clang/clang_gen.go:4:0:
../../../../.gvm/pkgsets/go1.7.5/global/src/github.com/go-clang/v3.8/clang/./clang-c/Index.h:952:10: note: declared here
 CXString clang_getDiagnosticCategoryName(unsigned Category);
          ^
# github.com/go-clang/v3.8/clang
/usr/bin/ld: cannot find -lclang
collect2: error: ld returned 1 exit status
zimmski commented 7 years ago

I tried this, and maybe we should document this somehow @marxriedl ?

Installing part (@gchallen I was missing "libclang-dev" at first, maybe that is what you are missing too?)

docker run -it --rm ubuntu:xenial bash
apt-get update
apt-get install llvm clang libclang-dev git wget
wget https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz
tar xvfz go1.7.5.linux-amd64.tar.gz -C /usr/local
export PATH=/usr/local/go/bin:$PATH
export GOPATH=/root/go

Environment

go version
go version go1.7.5 linux/amd64
clang -v
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
llvm-config --libdir
/usr/lib/llvm-3.8/lib
ls -l /usr/lib/llvm-3.8/lib/libclang*so
lrwxrwxrwx 1 root root 15 Jul 12  2016 /usr/lib/llvm-3.8/lib/libclang-3.8.0.so -> libclang-3.8.so
lrwxrwxrwx 1 root root 40 Jul 12  2016 /usr/lib/llvm-3.8/lib/libclang-3.8.so -> ../../x86_64-linux-gnu/libclang-3.8.so.1
lrwxrwxrwx 1 root root 40 Jul 12  2016 /usr/lib/llvm-3.8/lib/libclang.so -> ../../x86_64-linux-gnu/libclang-3.8.so.1

Installing go-clang (I had to add at least CC)

CC=clang CXX=clang++ CGO_LDFLAGS="-L`llvm-config --libdir`" go get -u github.com/go-clang/v3.8/...

EDIT: So basically I think you are missing the libclang.so symlink which comes with the libclang-dev package if I am not mistaken.

marxriedl commented 7 years ago

Possibly. You automated most of the stuff for setting up versions, which is somewhat document-ish, e.g., https://github.com/go-clang/gen/blob/master/scripts/switch-clang-version.sh

I usually also forget how to set up versions until I look into the scripts :D

gchallen commented 7 years ago

Doh—of course this works. And I feel like an idiot. Thanks for the help!