[Python-Dev] build problems under Solaris

Greg Ward gward@mems-exchange.org
Fri, 3 Nov 2000 17:45:00 -0500


On 03 November 2000, Martin von Loewis said:
> That happens only when using the system linker (/usr/ccs/bin/ld). The
> GNU linker won't complain, and the resulting executables will run
> fine.

I'm not sure which linker my GCC on Solaris is using.  (Even though,
umm, I built that GCC.  Errr...)  But ISTR that the choice of linker is
made when you build GCC, so it's not really an option here.  Bad enough
to tell people that they need to reinstall Python because they need some
extension; requiring them to rebuild GCC -- !

But it's not necessary at all, because...

> To make the system linker happy, you also need to compile the modules
> with -fPIC - which, according to Sun, we should have done all the time
> when building shared libraries. The linker complains about relocations
> in the text segment, which shouldn't be there - shared libraries
> should be position independent.

...compiling everything with -fPIC is exactly what the doctor ordered.
I added "-fPIC" to OPT in the Makefile and rebuilt, and everything went
smoothly when linking the extensions with "gcc -shared".  No problems
compiling or linking, and the tests are running right now without a
hitch.  Yaayyyyh!

So here's an update of the patch: this changes LDSHARED to "$(CC)
-shared" when using GCC under Solaris, and it adds "-fPIC" to OPT when
using GCC *anywhere*.  This seems like a good thing to me when building
shared objects, but if anyone is aware of a platform where "gcc
... -fPIC" is a bad idea, speak up now!

*** configure.in	2000/11/03 08:18:36	1.177
--- configure.in	2000/11/03 22:43:50
***************
*** 308,315 ****
  	case $GCC in
  	yes)
  		case $ac_cv_prog_cc_g in
! 		yes)	OPT="-g -O2 -Wall -Wstrict-prototypes";;
! 		*)	OPT="-O2 -Wall -Wstrict-prototypes";;
  		esac
  		;;
  	*)	OPT="-O";;
--- 308,315 ----
  	case $GCC in
  	yes)
  		case $ac_cv_prog_cc_g in
! 		yes)	OPT="-g -O2 -Wall -Wstrict-prototypes -fPIC";;
! 		*)	OPT="-O2 -Wall -Wstrict-prototypes -fPIC";;
  		esac
  		;;
  	*)	OPT="-O";;
***************
*** 564,570 ****
  	SunOS/4*) LDSHARED="ld";;
  	SunOS/5*) 
  		if test "$GCC" = "yes"
! 		then LDSHARED='$(CC) -G'
  		else LDSHARED="ld -G";
  		fi ;;
  	hp*|HP*) LDSHARED="ld -b";;
--- 564,570 ----
  	SunOS/4*) LDSHARED="ld";;
  	SunOS/5*) 
  		if test "$GCC" = "yes"
! 		then LDSHARED='$(CC) -shared'
  		else LDSHARED="ld -G";
  		fi ;;
  	hp*|HP*) LDSHARED="ld -b";;


I'll go update the bug report now.  Thanks, Martin!

        Greg