Caffe: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

Created on 20 Mar 2015  Â·  8Comments  Â·  Source: BVLC/caffe

I'm building caffe on aws ec2 micro instance, I change config file to build it with cpu support only

CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

but while running 'make' , I get error.

CXX src/caffe/syncedmem.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libgflags.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so] Error 1

Most helpful comment

I had a similar issue. To resolve required recompiling gflags as they suggested:

(1) edit CMakeCache.txt
(2) Change:
CMAKE_CXX_FLAGS:STRING=-fPIC
(3) re-compile and install.

All set : )

All 8 comments

I had a similar issue. To resolve required recompiling gflags as they suggested:

(1) edit CMakeCache.txt
(2) Change:
CMAKE_CXX_FLAGS:STRING=-fPIC
(3) re-compile and install.

All set : )

Thanks,

I changed
CMAKE_CXX_FLAGS:STRING='-fPIC '
to
CMAKE_CXX_FLAGS:STRING=-fPIC
in CMakeCache.txt in gflags folder and it works.

at first I use installations instractions from here
http://caffe.berkeleyvision.org/install_apt.html

wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make && make install

please ask usage questions on caffe-users -- this issues tracker is primarily for Caffe development discussion. Thanks!

/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

@choosehappy , it still has problem

@smilelhh
gflags is not compiled as a shared library by default; make sure it is compiled as a shared library:
cmake .. -DBUILD_SHARED_LIBS=ON
make -j2 && sudo make -j2 install

After following all the steps on ubuntu 16.04 sudo make install did the trick.

just recompile the gflags with CXXFLAGS += -fPIC makes things work

I had a similar error message and the suggested fixes above didn't work. But I found that I had an old installation of gflags that I had built from source, so I removed it by deleting the files /usr/local/lib/libgflags_nothreads.a and /usr/local/lib/libgflags.a, in addition to sudo rm -rf /usr/local/lib/cmake/gflags and sudo rm -rf /usr/local/include/gflags/.

Then to make sure I had a clean install with apt, I ran:

sudo apt purge libgflags-dev
sudo apt install libgflags-dev libgoogle-glog-dev

Then did a clean build and it worked!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ruhjkg picture Ruhjkg  Â·  3Comments

iamhankai picture iamhankai  Â·  3Comments

FreakTheMighty picture FreakTheMighty  Â·  3Comments

sdemyanov picture sdemyanov  Â·  3Comments

vladislavdonchev picture vladislavdonchev  Â·  3Comments