mudge/re2

linker problems on install on centos

Closed this issue · 4 comments

I tried to install this gem on a centos server and got a lot of linker errors.
I've installed it using:

gem install re2 -- --with-re2-dir=/home/user/.linuxbrew/Cellar/re2/20170701

The full log is the following:

current directory: /home/user/.gem/ruby/2.3.0/gems/re2-1.1.1/ext/re2
/package/host/localhost/ruby-2.3.4/bin/ruby -r ./siteconf20170801-14854-n2fme7.rb extconf.rb --with-re2-dir=/home/user/.linuxbrew/Cellar/re2/20170701
checking for main() in -lstdc++... yes
checking for stdint.h... yes
checking for rb_str_sublen()... yes
checking for main() in -lre2... yes
checking for re2 requires C++11 compiler... yes
checking for RE2::Match() with endpos argument... yes
creating Makefile

current directory: /home/user/.gem/ruby/2.3.0/gems/re2-1.1.1/ext/re2
make "DESTDIR=" clean

current directory: /home/user/.gem/ruby/2.3.0/gems/re2-1.1.1/ext/re2
make "DESTDIR="
compiling re2.cc
cc1plus: warning: command line option '-Wdeclaration-after-statement' is valid for C/ObjC but not for C++
cc1plus: warning: command line option '-Wimplicit-function-declaration' is valid for C/ObjC but not for C++
re2.cc: In function 'VALUE re2_matchdata_begin(VALUE, VALUE)':
re2.cc:350:16: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   re2_pattern *p;
                ^
re2.cc: In function 'VALUE re2_matchdata_end(VALUE, VALUE)':
re2.cc:380:16: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   re2_pattern *p;
                ^
linking shared-object re2.so
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(re2.o): relocation R_X86_64_32S against symbol `_ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(regexp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(strutil.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(bitstate.o): relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(compile.o): relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(dfa.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(nfa.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(onepass.o): relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(parse.o): relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(prog.o): relocation R_X86_64_32S against symbol `_ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(simplify.o): relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: /home/user/.linuxbrew/Cellar/re2/20170701/lib/libre2.a(tostring.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/user/.linuxbrew/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [re2.so] Error 1

make failed, exit code 2

I've installed re2 via linux brew:

re2: stable 20170701 (bottled), HEAD
Alternative to backtracking PCRE-style regular expression engines
https://github.com/google/re2
/home/user/.linuxbrew/Cellar/re2/20170701 (13 files, 25.1MB) *
  Poured from bottle on 2017-07-31 at 11:27:32
From: https://github.com/Linuxbrew/homebrew-core/blob/master/Formula/re2.rb
mudge commented

Hi @kanedo,

So that I can investigate this further, could you please let me know your version of CentOS and provide some steps to reproduce the issue (e.g. in VirtualBox)?

Hi @mudge ,
the centos version is CentOS release 6.9 (Final)

unfortunately this is happening on a shared hosting and i dont know their full setup

mudge commented

I was able to reproduce this on CentOS 6.9 using git, gcc, re2 and Ruby from Linuxbrew.

The problem seems to be with the version of re2 installed via Linuxbrew itself as it is not compiled correctly as a shared library (e.g. it seems to at least be missing the required -fPIC flag as the errors you saw indicate).

I was able to get the gem working by following the official re2 installation instructions, compiling my own version of re2 and then attempting to install the gem again.

As you're on shared hosting, does that mean you can't write anywhere outside your home directory? If so, you should still be able to compile to your own location like so (replace /home/user/.re2 with wherever you want to install the re2 library):

$ gcc --version
gcc (Homebrew gcc 5.3.) 5.3.0
$ ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58052) [x86_64-linux]
$ git clone https://code.googlesource.com/re2
$ cd re2
$ make prefix=/home/user/.re2
$ make test prefix=/home/user/.re2
$ make install prefix=/home/user/.re2
$ make testinstall prefix=/home/user/.re2
$ gem install re2 -- --with-re2-dir=/home/user/.re2

I hope that solves your issue and please let me know how you get on.

thank you very much @mudge that worked.
To use it with bundler also set bundle config build.re2 --with-re2-dir=/home/user/.re2