Thursday, May 11, 2017

Tensorflow custom operation - problem with word2vec operation

This is just a quick note for myself. One beautiful afternoon I got a below error:

undefined symbol: _ZN10tensorflow16ReadFileToStringEPNS_3EnvERKSsPSs
The distributed package of Tensorflow uses gcc 4.
If you compile from sources on more or less up to date Ubuntu or Debian, you probably will have gcc 5 or newer installed.
gcc 5 and gcc 4 ABI are not compatible, thus your Tensorflow and operations MUST be compiled with same ABI.
You have two choices either compile the Tensorflow with old ABI support by providing
flag to bazel build or ensure your operations are compiled with new ABI.
You can also force gcc5 to use old ABI (source):

TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
g++ -std=c++11 -shared \

More could be found in Tensorflow doc:


Friday, January 27, 2017

To shadow or to not?

Long story short: it's easy to accidentally shadow a variable by using := operator in if statement. Be aware:

package main

import (

func f() (int, int) { return 2, 2 }

func main() {
 var x = 1
 if x, y := f(); x == y {
  fmt.Printf("%d %d\n", x, y)
 fmt.Printf("%d\n", x)
 x, y := f()
 fmt.Printf("%d %d\n", x, y)
The output is:

2 2
2 2
Run in Golang Play: