Tuesday, 12 April 2016

Bro compilation issues: ImportError: No module named _sqlite3 and /usr/local/lib/libpython2.7.a: could not read symbols: Bad value

I was compiling bro-2.4.1 from source and encountered some strange issues during compilation.

The first error I encountered - "No module named sqlite3" even though I have installed python2.7 as requested in bro documentation:

-- Found SubnetTree: build from source aux/pysubnettree 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3
CMake Error at aux/broctl/CMakeLists.txt:65 (message):
  The sqlite3 python module is required to use BroControl, but was not found.
  Configuration aborted.

If you have not installed subnettree package, please install it using pip:

#pip install pysubnettree

If you have installed subnettree package and still getting the error then install sqlite3-devel package:

#yum install sqlite-devel

After this, re-compile python2.7 once again:

#./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared
# make
# make altinstall
# ln-s /usr/local/bin/python2.7 /usr/bin/python2.7
# ln-s /usr/local/bin/pip2.7 /usr/bin/pip2.7

If you already have python2.6 installed, you can also do:

# cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/

Often I miss is setting of environment variables before compilation:
# export LDFLAGS=-L/usr/local/lib
# export CFLAGS=-I/usr/local/include
# export CPPFLAGS=-I/usr/local/include
# export LB_LIBRARY_PATH=-I/usr/local/lib
# export CFLAGS="$CFLAGS -fPIC"

So, don't forget them!!

You may also encounter the following strange error during bro compilation:

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[3]: *** [aux/broctl/aux/pysubnettree/_SubnetTree.so] Error 1
make[3]: Leaving directory `/home/admin/Downloads/src_packages/bro-2.4.1/build'
make[2]: *** [aux/broctl/aux/pysubnettree/CMakeFiles/_SubnetTree.dir/all] Error 2
make[2]: Leaving directory `/home/admin/Downloads/src_packages/bro-2.4.1/build'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/admin/Downloads/src_packages/bro-2.4.1/build'
make: *** [all] Error 2

This error occurs when your python version is compiled without using --enable-shared option. So, to avoid this error, use the following:

[psj@ids Python-2.7.10]# ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared

or with LDFLAGS:

[psj@ids Python-2.7.10]# ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS='-Wl,-rpath /usr/local/lib'

Basically,  re-compile python followed by bro once again -

[psj@ids Python-2.7.10]# ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS='-Wl,-rpath /usr/local/lib'
[psj@ids Python-2.7.10]# make
[psj@ids Python-2.7.10]# make install

Now, compile bro:
[psj@ids bro-2.4.1]# ./configure

[psj@ids bro-2.4.1]# make
[psj@ids bro-2.4.1]# make install

Some time, you may also have to delete any previous file:
[psj@ids Python-2.7.10]# rm /usr/local/lib/libpython2.7.a
rm: remove regular file `/usr/local/lib/libpython2.7.a'? y


The following links are useful while debugging:
1) https://code.google.com/archive/p/modwsgi/wikis/InstallationIssues.wiki#Mixing_32_Bit_And_64_Bit_Packages
2) https://groups.google.com/forum/#!searchin/modwsgi/$2Fusr$2Flocal$2Flib$2Flibpython2.7.a$3A$20could$20not$20read$20symbols$3A$20Bad$20value/modwsgi/i3-QlhC62WI/dG06OvgkaMQJ

No comments:

Post a Comment