LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Possible 32 bit / 64 bit compatibility issues when compiling from source (https://www.linuxquestions.org/questions/slackware-14/possible-32-bit-64-bit-compatibility-issues-when-compiling-from-source-4175671714/)

thethinker 03-20-2020 04:05 PM

Possible 32 bit / 64 bit compatibility issues when compiling from source
 
So I am trying to install SageMath from source (actually, I'm using the SlackBuilds script, but I *wrote* that script, so....), and some libraries are not linking correctly. I'm in contact with the developers, and they've said that the following lines:

Code:

/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible ///usr/lib/libm.so when searching for -lm
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible ///usr/lib/libm.a when searching for -lm
/usr/lib/libgmp.so: error adding symbols: File in wrong format

"are suspicious", and suggest that the problem is related to cross-compilation issues. That checks out - the SlackBuilds script works as intended on a vanilla Slackware installation. However, the machine I'm on now has multilib enabled, following the SlackDocs tutorial (https://docs.slackware.com/slackware:multilib). Their actual suggestion was to "reinstall gmp", but I'm afraid of doing that blind, since I might replace a single 64 bit library with a 32 bit one!

I can see that gmp is indeed one of the packages that had the 32-bit compatability done on it. Is it possible something went wrong in that process? It's kinda likely that I screwed it up, but I haven't noticed anything like this yet, and that was some time ago.

Code:

$ uname -a
Linux Zonadar 4.4.14 #1 SMP Fri Jun 24 13:30:15 CDT 2016 x86_64 Intel(R) Core(TM) i5 CPU        760  @ 2.80GHz GenuineIntel GNU/Linux


BW-userx 03-20-2020 04:11 PM

maybe try using a sandbox
14.2 > System > sandbox (2.18)
Using chroot to build sandbox environment

ehartman 03-20-2020 04:14 PM

Quote:

Originally Posted by thethinker (Post 6102710)
suggest that the problem is related to cross-compilation issues. That checks out - the SlackBuilds script works as intended on a vanilla Slackware installation.

That is correct, your 64-bit compilation tries to link against 32-bit libm and libgmp (and maybe others, I cannot tell from your quote).
Maybe you should add an explicit -L/usr/lib64 -L/lib64 to your compile commandline(s), to make sure it finds the 64-bit libraries first before any 32-bit ones.
I never used a multi-lib system myself and haven't seen your SlackBuild, but in Slackware the libraries in /usr/lib:/lib (which are by default added at the end of the commandline) are the 32-bit ones, the 64-bit libraries always are in directories that end on 64, like /usr/lib64, /usr/local/lib64, etc.

mickski56 03-21-2020 08:22 AM

As @ehartman says and from https://slackbuilds.org/faq/#multilib

If you are using multilib packages from somewhere and also have some 32bit packages installed, then you might run into problems with the build process trying to link 32bit libraries instead of 64bit libraries. If this occurs, it can probably be solved by placing the following line:
LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}" \after the lines for CFLAGS and CXXFLAGS passed to the configure script. In other words, make it look something like this:
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}" \
./configure \

Beyond that, you are on your own. This is an unsupported setup.

Other things to think about
Does /usr/lib64/libgmp.so actually exist and point to something ?
How is your PKG_CONFIG_PATH set, does it list /usr/lib64 & /usr/local/lib64 before anything else ?
Search config.log for libgmp and see if you can work out what's going wrong.
Run configure and see if you can bypass pkg-config for the offending library (unlikely in this case i think)

Explicit LDFLAGS added to the slackbuild work 9 times out of 10.
hth

orbea 03-21-2020 09:23 AM

Please share a complete build log.

Code:

./SageMath.SlackBuild 2>&1 | tee /tmp/sagemath.log
Its impossible for us to tell if those errors are the real issue or not with the information provided.

Quote:

Originally Posted by BW-userx (Post 6102711)

That sandbox doesn't do what you think it does. :)

Its used to prevent build scripts from breaking free from their DESTDIR and writing/modifying files directly to the file system.

Code:

sandbox ./foo.SlackBuild
It will not help building SageMath, but maybe it could help find an unrelated bug(s) in the SageMath build script or build system.

thethinker 03-23-2020 01:14 PM

Quote:

Originally Posted by orbea (Post 6102892)
Please share a complete build log.

Code:

./SageMath.SlackBuild 2>&1 | tee /tmp/sagemath.log
Its impossible for us to tell if those errors are the real issue or not with the information provided.

Done, you can check it out here:

https://www.dropbox.com/s/grmxmpdb7clxfcx/sage.log?dl=0

thethinker 03-23-2020 01:24 PM

Quote:

Originally Posted by mickski56 (Post 6102885)
As @ehartman says and from https://slackbuilds.org/faq/#multilib

If you are using multilib packages from somewhere and also have some 32bit packages installed, then you might run into problems with the build process trying to link 32bit libraries instead of 64bit libraries. If this occurs, it can probably be solved by placing the following line:
LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}" \after the lines for CFLAGS and CXXFLAGS passed to the configure script. In other words, make it look something like this:
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}" \
./configure \

Beyond that, you are on your own. This is an unsupported setup.

Well this is great - the SlackBuilds script does not invoke .configure. I guess that's bad form anyway, and I'll see if I can fix it.

(I took over maintenance of this script, because it was orphaned. So it's my responsibility now!)

mickski56 03-23-2020 02:16 PM

Sorry is the slackbuild academic/sage/sage.SlackBuild ?

If so try
LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}" \
make build

orbea 03-23-2020 03:09 PM

Quote:

Originally Posted by thethinker (Post 6103581)

Thanks, this seems to be the problem.

Code:

[iml-1.0.4p1.p2] /usr/lib/libgmp.so: error adding symbols: File in wrong format
For reference the full error.

Code:

[iml-1.0.4p1.p2] /usr/bin/bash ../libtool --tag=CC  --mode=link gcc -I///usr/include -I/tmp/SBo/sage-9.0/local/include  -I. -O3 -g  -version-info 1:1:1  -L/tmp/SBo/sage-9.0/local/lib -Wl,-rpath,/tmp/SBo/sage-9.0/local/lib  -lm -o libiml.la -rpath /tmp/SBo/sage-9.0/local/lib libiml_la-basisop.lo libiml_la-certsolve.lo libiml_la-error.lo libiml_la-latreduce.lo libiml_la-memalloc.lo libiml_la-mtrans.lo libiml_la-nonsysolve.lo libiml_la-padiclift.lo libiml_la-reconsolu.lo libiml_la-RNSop.lo libiml_la-nullspace.lo -L///usr/lib -lgmp -L/tmp/SBo/sage-9.0/local/lib -lgmp -L/tmp/SBo/sage-9.0/local/lib -L/tmp/SBo/sage-9.0/local/lib -lopenblas 
[iml-1.0.4p1.p2] libtool: link: gcc -shared  -fPIC -DPIC  .libs/libiml_la-basisop.o .libs/libiml_la-certsolve.o .libs/libiml_la-error.o .libs/libiml_la-latreduce.o .libs/libiml_la-memalloc.o .libs/libiml_la-mtrans.o .libs/libiml_la-nonsysolve.o .libs/libiml_la-padiclift.o .libs/libiml_la-reconsolu.o .libs/libiml_la-RNSop.o .libs/libiml_la-nullspace.o  -L/tmp/SBo/sage-9.0/local/lib -lm -L///usr/lib /usr/lib/libgmp.so -lopenblas  -O3 -Wl,-rpath -Wl,/tmp/SBo/sage-9.0/local/lib  -Wl,-soname -Wl,libiml.so.0 -o .libs/libiml.so.0.1.1
[iml-1.0.4p1.p2] /usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible ///usr/lib/libm.so when searching for -lm
[iml-1.0.4p1.p2] /usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible ///usr/lib/libm.a when searching for -lm
[iml-1.0.4p1.p2] /usr/lib/libgmp.so: error adding symbols: File in wrong format
[iml-1.0.4p1.p2] collect2: error: ld returned 1 exit status
[iml-1.0.4p1.p2] Makefile:373: recipe for target 'libiml.la' failed
[iml-1.0.4p1.p2] make[6]: *** [libiml.la] Error 1
[iml-1.0.4p1.p2] make[6]: Leaving directory '/tmp/SBo/sage-9.0/local/var/tmp/sage/build/iml-1.0.4p1.p2/src/src'
[iml-1.0.4p1.p2] Makefile:339: recipe for target 'all-recursive' failed
[iml-1.0.4p1.p2] make[5]: *** [all-recursive] Error 1
[iml-1.0.4p1.p2] make[5]: Leaving directory '/tmp/SBo/sage-9.0/local/var/tmp/sage/build/iml-1.0.4p1.p2/src'
[iml-1.0.4p1.p2] Makefile:270: recipe for target 'all' failed
[iml-1.0.4p1.p2] make[4]: *** [all] Error 2
[iml-1.0.4p1.p2] make[4]: Leaving directory '/tmp/SBo/sage-9.0/local/var/tmp/sage/build/iml-1.0.4p1.p2/src'

This shows the problem is not in sagemath, but in iml-1.0.4p1, specifically in the file "config/gmp-check.m4" which hardcodes "lib". I think the correct solution would be to replace the gmp-check.m4 file with a proper pkg-config check.

Additionally sage-math further hardcodes it in "build/pkgs/iml/spkg-install".

Code:

# When using GMP from a standard system location it shouldn't really
# matter what we put here, but iml's configure script requires we
# provide *something*, and this should be reasonable in most cases
SAGE_GMP_LIB="`echo "$SAGE_GMP_INCLUDE" | sed 's|/include|/lib|'`"

sdh_configure --enable-shared \
              --with-default="$SAGE_LOCAL" \
              --with-gmp-include="$SAGE_GMP_INCLUDE" \
              --with-gmp-lib="$SAGE_GMP_LIB" \
              --with-cblas="$(pkg-config --libs cblas)" \
              --with-cblas-include="$(pkg-config --cflags cblas)" \
              "$IML_CONFIGURE"

A quick workaround would be to add this to the slackbuild.

Code:

sed -i "s|/lib|/lib${LIBDIRSUFFIX}|" build/pkgs/iml/spkg-install
There may be other places that require similar fixes.

mickski56 03-23-2020 06:06 PM

Quote:

Originally Posted by mickski56 (Post 6103600)
Sorry is the slackbuild academic/sage/sage.SlackBuild ?

If so try
LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}" \
make build

I have just tried this and sage at least built without error on my multilib install.
You will also need to add

if [ "$ARCH" = "i586" ]; then
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
LIBDIRSUFFIX="64"
else
LIBDIRSUFFIX=""
fi

somewhere just after the arch detection section of the slackbuild in order to set LIBDIRSUFFIX.
Also LIBDIRSUFFIX should probably be LIBSUFFIX

orbea 03-23-2020 06:13 PM

Quote:

Originally Posted by mickski56 (Post 6103644)
Also LIBDIRSUFFIX should probably be LIBSUFFIX

LIBDIRSUFFIX is the what the templates contain and is standardized.

https://slackbuilds.org/templates/

bassmadrigal 03-23-2020 09:18 PM

Quote:

Originally Posted by orbea (Post 6103647)
LIBDIRSUFFIX is the what the templates contain and is standardized.

https://slackbuilds.org/templates/

It might be standardized, but it isn't included in the sage.SlackBuild script.

orbea 03-23-2020 09:39 PM

Maintainers are welcome to remove it in the case the build script doesn't use it and sage might not need it if their build system was fixed...

thethinker 03-25-2020 02:42 PM

Quote:

Originally Posted by mickski56 (Post 6103644)
I have just tried this and sage at least built without error on my multilib install.
You will also need to add

if [ "$ARCH" = "i586" ]; then
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
LIBDIRSUFFIX="64"
else
LIBDIRSUFFIX=""
fi

somewhere just after the arch detection section of the slackbuild in order to set LIBDIRSUFFIX.
Also LIBDIRSUFFIX should probably be LIBSUFFIX

Can you be more specific, like maybe attach your working script? I added these lines

Code:

if [ "$ARCH" = "i586" ]; then
    LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
    LIBDIRSUFFIX="64"
else
    LIBDIRSUFFIX=""
fi

After the SAGEROOT declaration, and then this line

Code:

LDFLAGS="-L/usr/lib${LIBDIRSUFFIX}"
right before the "make build" command, and the error persists. Here's mine:

https://www.dropbox.com/s/ed7r18j02e...lackBuild?dl=0

BW-userx 03-25-2020 03:01 PM

the big thing I learned about install scripts is, that they can be edited to suit ones needs and to make it work, if is doesn't as it is already written.
Just saying.


All times are GMT -5. The time now is 12:08 PM.