Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"undefined symbol: _ZNK6google8protobuf7Message11GetTypeNameEv", g++-4.9 #45

Closed
hughperkins opened this issue Jan 30, 2016 · 14 comments
Closed

Comments

@hughperkins
Copy link
Contributor

Installed as follows, on ubuntu 15.10:

export CC=gcc-4.9
export CXX=g++-4.9
sudo apt-get install -y libprotobuf-dev protobuf-c-compiler protobuf-compiler
luarocks install loadcaffe

Test as follows:

luajit -l loadcaffe

What I expect to happen:

  • silently runs, no error messages

What actually happens:

luajit: /home/ubuntu/torch/install/share/lua/5.1/loadcaffe/ffi.lua:10: /home/ubuntu/torch/install/lib/lua/5.1/libloadcaffe.so: undefined symbol: _ZNK6google8protobuf7Message11GetTypeNameEv
stack traceback:
    [C]: in function 'load'
    /home/ubuntu/torch/install/share/lua/5.1/loadcaffe/ffi.lua:10: in main chunk
    [C]: in function 'dofile'
    /home/ubuntu/torch/install/share/lua/5.1/torch/init.lua:49: in function 'include'
    /home/ubuntu/torch/install/share/lua/5.1/loadcaffe/init.lua:3: in main chunk
    [C]: at 0x0046b7a0
    [C]: at 0x00406670
@hughperkins
Copy link
Contributor Author

Gist of build and output here: https://gist.github.com/hughperkins/da764a09b37a84e67684

Edit: protobuf version:

dpkg -l libprotobuf-dev | grep ii
ii  libprotobuf-dev:amd64 2.6.1-1.2    amd64        protocol buffers C++ library (development files)

@hughperkins
Copy link
Contributor Author

Oh... looks like since protobuf is a c++ library, needs gcc-5 to build it, on ubuntu 15.10. (Different from the cuda libraries, which needs 4.9 to build, since cuda toolkit doesnt work with gcc-5).

CC=
CXX=
rm -Rf build
luarocks make loadcaffe-1.0.0-rockspec
luajit -l loadcaffe

=> works ok

@jayanthkoushik
Copy link

Hi, I'm having the same issue even with gcc-5.4.0. Any ideas? It's the exact same issue. https://gist.github.com/jayanthkoushik/6b90eaad95ced5b7d0aa0762b34d60bf.

@jayanthkoushik
Copy link

Ah, I think I see the problem. It sets the runtime path to $ORIGIN/../lib. But protobuf isn't there. Is there any way to change this?

@andrefaraujo
Copy link

@jayanthkoushik were you able to solve this? My error message is exactly the same as yours. I'd think the linking would work correctly, since this is what I get when I do an "ldd" on libloadcaffe:

$ ldd /home/afaraujo/torch/install/lib/lua/5.1/libloadcaffe.so
linux-vdso.so.1 =>  (0x00007fff985f8000)
libTH.so => /home/afaraujo/torch/install/lib/libTH.so (0x00007fb949ca0000)
libprotobuf.so.9 => /share/sw/free/protobuf/2.6.1rc1/lib/libprotobuf.so.9 (0x00007fb949820000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb9495ea000)
libblas.so.3 => /usr/lib64/libblas.so.3 (0x00007fb949393000)
liblapack.so.3 => /usr/lib64/liblapack.so.3 (0x00007fb948b81000)
librt.so.1 => /lib64/librt.so.1 (0x00007fb948979000)
libstdc++.so.6 => /share/sw/free/gcc/5.3.0/lib64/libstdc++.so.6 (0x00007fb9485eb000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb948366000)
libgcc_s.so.1 => /share/sw/free/gcc/5.3.0/lib64/libgcc_s.so.1 (0x00007fb948150000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb947dbc000)
libgomp.so.1 => /share/sw/free/gcc/5.3.0/lib64/libgomp.so.1 (0x00007fb947b9a000)
/lib64/ld-linux-x86-64.so.2 (0x0000003711a00000)
libz.so.1 => /lib64/libz.so.1 (0x00007fb947984000)
libgfortran.so.3 => /share/sw/free/gcc/5.3.0/lib64/libgfortran.so.3 (0x00007fb947663000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb94745f000)
libquadmath.so.0 => /share/sw/free/gcc/5.3.0/lib/../lib64/libquadmath.so.0 (0x00007fb947220000)

libprotobuf has the correct path, but still "luajit -l loadcaffe" fails exactly like it fails for you... any help would be appreciated!

@jayanthkoushik
Copy link

@andrefaraujo No, I was not :-(

@andrefaraujo
Copy link

@jayanthkoushik I was able to fix this by installing the most recent protobuf library (I cloned to a local directory from github here). I followed these instructions, except that I installed it to my home folder instead of to the default location. This is done by using the prefix option when issuing the configure command:

./configure --prefix=/home/afaraujo/protobuf

After building this new protobuf version, you can actually see that the "_ZNK6google8protobuf7Message11GetTypeNameB5cxx11Ev" symbol is there!

$ grep _ZNK6google8protobuf7Message11GetTypeNameB5cxx11Ev /home/afaraujo/protobuf/lib/libprotobuf.so
Binary file /home/afaraujo/protobuf/lib/libprotobuf.so matches

In the CMakeLists.txt for the loadcaffe package, make sure to add the following lines (of course, change the path accordingly):

SET(PROTOBUF_LIBRARY "/home/afaraujo/protobuf/lib/libprotobuf.so")
SET(PROTOBUF_INCLUDE_DIR "/home/afaraujo/protobuf/include/")
SET(PROTOBUF_PROTOC_EXECUTABLE "/home/afaraujo/protobuf/bin/protoc")

Then, in the loadcaffe path, run:

luarocks make loadcaffe-1.0-0.rockspec

and then it works :) hopefully this works for you too...

@hughperkins
Copy link
Contributor Author

I think the issue is caused by a mismatch between the g++ version used to build the protobuf library, and that used to build loadcaffe.

Installing the latest version of protobuf, as per @andrefaraujo , my guess is, solves the issue, becuase the library is being rebuilt with the same version of g++ as loadcaffe? It's not certain, but I feel it could be a hypothesis worth double-checking perhaps?

@victoriastuart
Copy link

I had this issue. I generally use Anaconda virtual environments to isolate packages/installs, but got lazy and for convenience had caffe, and then later tensorflow installed in a py27 venv. The problem is multiply-present "protobuf" installs; in my case, via pip and conda.

On my Arch Linux system I needed the pip-installed protobuf ("pip install protobuf") for my caffe install,

pip list | grep -i protobuf
    protobuf (3.1.0.post1)

but tensoflow (installed via "conda install -c conda-forge tensorflow") installed the following:

protobuf:   3.0.0-py27_0  conda-forge
tensorflow: 0.11.0-py27_0 conda-forge

Go ahead and remove all those protobuf versions

pip uninstall  protobuf
conda uninstall protobuf
conda uninstall libprotobuf    ## if present

then delete and reinstall caffe:

git clone https://github.com/BVLC/caffe
cd caffe
# edit "Makefile.config" file per your system, needs
make all -j8    ## 8 cores on my Intel CPU
# add pycaffe your $PYTHONPATH
export PYTHONPATH=${PYTHONPATH}:/mnt/Vancouver/apps/caffe/python/
#  can also add to ~/.bashrc or your preferred "$PYTHONPATH" file ..
make pycaffe
pip install protobuf

I am again able to import caffe in my py27 venv, without the "undefined symbol: _ZNK6google8protobuf7Message11GetTypeNameEv..." error.

I just then went ahead and reinstalled tensorflow,

conda install -c conda-forge tensorflow

with the caveat that on on subsequent caffe or tensorflow updates I may need to repeat this process; due to this mess:

pip list | grep -i protobuf
    protobuf (3.1.0.post1)

conda list | grep -i protobuf
    protobuf                  3.1.0.post1               <pip>
    protobuf                  3.0.0                    py27_0    conda-forge

Meh ! :-/

But I can import my packages, again:

>>> import caffe
>>> import tensorflow
>>> tensorflow.__version__
    '0.11.0'
>>> import cv2
>>> import keras
    Using Theano backend.
>>> import scipy
>>> import theano
>>> import numpy
>>> ## ...

@archenroot
Copy link

Same happened here on Gentoo system with gcc 6.2.0, I just reinstalled latest version -> dev-libs/protobuf-3.1.0::gentoo

And now the error dissapeared.

@b4zz4
Copy link

b4zz4 commented Apr 7, 2017

sudo $(which luarocks) install loadcaffe
I use this and fix

@lijiansong
Copy link

We can install loadcaffe from the original source code, by

git clone https://github.com/szagoruyko/loadcaffe.git
cd loadcaffe
luarocks make loadcaffe-1.0-0.rockspec

if you have some problems as @andrefaraujo mentioned, you have to build libprotobuf from its source code, set libprotobuf path in the CMakeLists.txt for this loadcaffe package, then

cd loadcaffe
luarocks make loadcaffe-1.0-0.rockspec

@hlnull
Copy link

hlnull commented Nov 29, 2017

Share my solution first. These two commands solved my problem.

sudo apt-get install protobuf-compiler
sudo $(which luarocks) install loadcaffe

Hi, sudo $(which luarocks) install loadcaffe did solve this problem on my computer. Thanks.

I checked the logs of sudo $(which luarocks) install loadcaffe and luarocks install loadcaffe and found a little difference:

sudo $(which luarocks) install loadcaffe:

-- Set runtime path of "/home/name/torch/install/lib/luarocks/rocks/loadcaffe/1.0-0/lib/libloadcaffe.so" to "$ORIGIN/../lib:/home/name/torch/install/lib"

luarocks install loadcaffe:

-- Set runtime path of "/home/name/torch/install/lib/luarocks/rocks/loadcaffe/1.0-0/lib/libloadcaffe.so" to "$ORIGIN/../lib:/home/name/torch/install/lib:/home/name/anaconda2/lib"

Running luarocks without sudo include /home/name/anaconda2/lib. It is weird since loadcaffe shall have nothing to do with anaconda2, which is used in python. Then I remembered I installed protobuf in the anaconda2 environment. It seems luajit found the protobuf.lib in /home/name/anaconda2/lib instead of correct lib.

So check the logs and make sure nothing weird happens.

Besides, there might be some methods in lua to find which protobuf I am using, right? Does anyone knows the answer?

@xingdi1990
Copy link

Tried all the methods mentioned above, does not work for me. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants