classification
Title: Error while building Python from source
Type: compile error Stage: resolved
Components: Build Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Redcxx, zach.ware
Priority: normal Keywords:

Created on 2019-09-11 13:47 by Redcxx, last changed 2019-09-11 16:14 by zach.ware. This issue is now closed.

Messages (8)
msg351880 - (view) Author: Redcxx (Redcxx) Date: 2019-09-11 13:47
Python failed `make` when building from source if `--enabled-share` is pass in when running `./configure`.

````
...(some output which seem irrevelent)
/bin/ld: /home/e38160wl/Python3.7.4/local/lib/libssl.a(s3_meth.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/home/e38160wl/Python3.7.4/local/lib/libssl.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
ln: failed to access ‘libpython3.7m.so.1.0’: No such file or directory
make: *** [libpython3.7m.so] Error 1

````

I tried adding `CFLAGS="-fPIC"` as parameter of `./configure` but it does not make any changes
msg351897 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-09-11 14:21
Could you add some more details about what you're doing here, such as OS, OS version, compiler and compiler version, etc.?  We routinely test `--enable-shared` builds on both Linux and FreeBSD in our post-merge buildbot setup, and have not had any issues with this.

I also note that the error mentions `libssl.a`; what version of which SSL library are you using?
msg351910 - (view) Author: Redcxx (Redcxx) Date: 2019-09-11 14:40
Sorry for that,

Heres are my os infomation:
LSB Version:	:core-4.1-amd64:core-4.1-ia32:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-ia32:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-ia32:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	Scientific
Description:	Scientific Linux release 7.3 (Nitrogen)
Release:	7.3
Codename:	Nitrogen

I am using Linux as follows:
Linux e-c07kilf3145.it.manchester.ac.uk 3.10.0-514.el7.x86_64 #1 SMP Thu Nov 3 15:10:49 CDT 2016 x86_64 x86_64 x86_64 GNU/Linux

I am using the latest openssl release:
2019-Sep-10 13:53:14  	openssl-1.0.2t.tar.gz

*I made a change in the Modules/Setup.dist as my openssl is not in the default location:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/home/e38160wl/local/openssl
ssl_path=/home/e38160wl/local
_ssl _ssl.c \
	-DUSE_SSL -I$(ssl_path)/include -I$(ssl_path)/include/openssl \
	-L$(ssl_path)/lib -lssl -lcrypto
msg351915 - (view) Author: Redcxx (Redcxx) Date: 2019-09-11 14:54
Sorry I mistype the changes I made in Modules/Setup.dist, this is the correct one:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/home/e38160wl/Python3.7.4/local/openssl
ssl_path=/home/e38160wl/Python3.7.4/local
_ssl _ssl.c \
	-DUSE_SSL -I$(ssl_path)/include -I$(ssl_path)/include/openssl \
	-L$(ssl_path)/lib -lssl -lcrypto
msg351919 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-09-11 15:01
I believe the better option would be to pass `CPPFLAGS=-I/home/e38160wl/local/openssl/include LDFLAGS=-L/home/e38160wl/local/openssl/lib` instead of editing Setup[.dist].  Could you give that a try?

Otherwise, this may be an issue with the way OpenSSL was built; you could try leaving out all SSL-related changes and see if everything but `_ssl` and `_hashlib` builds correctly.
msg351950 - (view) Author: Redcxx (Redcxx) Date: 2019-09-11 15:39
That works, but I notice some message somewhere near the end of running `make`:
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2                  _hashlib              _lzma              
_sqlite3              _ssl                  _tkinter           
_uuid                 readline                                 
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd                
time                                                           


Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

And after `make install`, python is not running as expected:
$ python3
python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory
msg351953 - (view) Author: Redcxx (Redcxx) Date: 2019-09-11 15:47
not sure if it is related but I am installing Python in a different directory and I have added that to the prefix option when runnning configure.
msg351967 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-09-11 16:14
Ok, that shows that the issue is not actually with the Python build, but with trying to find the right incantation for both OpenSSL and Python to get what you want :).  As such I'm going to go ahead and close the issue.

As for getting you going, there is a bit of headache involved in getting the dynamic library search path correct; if you're installing in exotic locations, you may need to add entries in `/etc/ld.conf.d/` (and run `ldconfig`).  Hopefully this gives you enough hints to search for to get you to where you want!
History
Date User Action Args
2019-09-11 16:14:00zach.waresetstatus: open -> closed
resolution: not a bug
messages: + msg351967

stage: test needed -> resolved
2019-09-11 15:47:24Redcxxsetmessages: + msg351953
2019-09-11 15:39:36Redcxxsetmessages: + msg351950
2019-09-11 15:01:12zach.waresetmessages: + msg351919
stage: test needed
2019-09-11 14:54:23Redcxxsetmessages: + msg351915
2019-09-11 14:42:29Redcxxsettype: crash -> compile error
2019-09-11 14:40:59Redcxxsettype: compile error -> crash
messages: + msg351910
2019-09-11 14:21:09zach.waresettype: crash -> compile error

messages: + msg351897
nosy: + zach.ware
2019-09-11 13:47:43Redcxxcreate