TensorFlow for Go演示示例运行失败。

huangapple go评论84阅读模式
英文:

TensorFlow for Go demo example run failed

问题

我有一个问题。

环境

macbookpro:lib fredlee$ go version
go version go1.8.3 darwin/amd64
macbookpro:lib fredlee$ pwd
/usr/local/lib
macbookpro:lib fredlee$ ls -alh libtensorflow.so
-r-xr-xr-x 1 root wheel 102M 1 1 1970 libtensorflow.so
macbookpro:lib fredlee$ file libtensorflow.so
libtensorflow.so: Mach-O 64-bit dynamically linked shared library x86_64
macbookpro:lib fredlee$

问题

macbookpro:~ fredlee$ go get
github.com/tensorflow/tensorflow/tensorflow/go macbookpro:~ fredlee$
go test github.com/tensorflow/tensorflow/tensorflow/go

github.com/tensorflow/tensorflow/tensorflow/go ld: library not found for -ltensorflow clang: error: linker command failed with exit code 1

(use -v to see invocation)
FAIL github.com/tensorflow/tensorflow/tensorflow/go [build failed]

有人可以帮我让它工作吗?

英文:

i have the issue.

environment
> macbookpro:lib fredlee$ go version
> go version go1.8.3 darwin/amd64
> macbookpro:lib fredlee$ pwd
> /usr/local/lib
> macbookpro:lib fredlee$ ls -alh libtensorflow.so
> -r-xr-xr-x 1 root wheel 102M 1 1 1970 libtensorflow.so
> macbookpro:lib fredlee$ file libtensorflow.so
> libtensorflow.so: Mach-O 64-bit dynamically linked shared library x86_64
> macbookpro:lib fredlee$
>
>
>
>

issue

> macbookpro:~ fredlee$ go get
> github.com/tensorflow/tensorflow/tensorflow/go macbookpro:~ fredlee$
> go test github.com/tensorflow/tensorflow/tensorflow/go
> # github.com/tensorflow/tensorflow/tensorflow/go ld: library not found for -ltensorflow clang: error: linker command failed with exit code 1
> (use -v to see invocation)
> FAIL	github.com/tensorflow/tensorflow/tensorflow/go [build failed]

anyone can help me make it works?

答案1

得分: 3

错误非常明显:

> ld: 找不到库 -ltensorflow

当你运行 go test 时,你正在调用编译器编译所需的库、测试文件,然后执行它们。

当编译一个使用了“非纯粹”Go库的程序时,你必须让编译器(和链接器)知道这个库的存在。

在编译阶段,编译器会在环境变量中列出的路径中查找库:

在 macOS 和 Linux 上是 LIBRARY_PATH

因此,你需要将编译后的库的位置添加到这个变量中。

例如,我有:

TFGOLIB="${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow"
export LIBRARY_PATH="${TFGOLIB}:${LIBRARY_PATH}"

在运行时,操作系统会查找库以执行动态链接。

因此,你需要将这个变量(Linux 上是 LD_LIBRARY_PATH,macOS 上是 DYLD_LIBRARY_PATH)设置为相同的位置。

此外,我建议你还将CUDA库的路径添加到这个变量中,以便在运行时可用。

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/cuda/lib64:/opt/cuda/extras/CUPTI/lib64:/opt/cudnn5.1/cuda/lib64:${TFGOLIB}"
英文:

The error is pretty clear:

> ld: library not found for -ltensorflow

When you run go test you're invoking the go compiler that compiles the required libraries, your test files and then executes them.

When you compile a program that uses a "non-pure" go library, you have to make the compiler (and the linker) aware of the library.

In the compilation phase, the compiler looks for the libraries (also) in the paths listed into the environment variable:

LIBRARY_PATH on OS X & Linux.

Thus you have to add into this variable the location of the compiled library.

For example I have:

TFGOLIB="${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow"
export LIBRARY_PATH="${TFGOLIB}:${LIBRARY_PATH}"

During the runtime, instead, the os looks for the library in order to perform dynamic linking.

Thus you have to set this other variable (LD_LIBRARY_PATH on Linux and DYLD_LIBRARY_PATH on OS X) to the same location.

Moreover I suggest you to also add the CUDA library path to this variable, in order to make it available at runtime.

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/cuda/lib64:/opt/cuda/extras/CUPTI/lib64:/opt/cudnn5.1/cuda/lib64:${TFGOLIB}"

答案2

得分: 0

我不太明白为什么你要测试一个第三方包。但从你的错误信息来看,似乎找不到一个名为ld的库。如果这个库是包的依赖项,那么我认为它应该已经安装在$GOPATH/bin目录下。所以,请尝试执行以下命令:

export PATH=$PATH:$GOPATH/bin
英文:

I do not quit understand why you test a third-party package. But from your error, looks like a lib called ld is not found. If it is needed the the package, then I believe It should be installed in the $GOPATH/bin. So, please try:

export PATH=$PATH:$GOPATH/bin

huangapple
  • 本文由 发表于 2017年6月8日 15:04:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/44428816.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定