Discussion:
Long shot question
(too old to reply)
root
2024-05-07 02:58:24 UTC
Permalink
Before searching for some Raspberry PI 5 group, I'll post
my problem here, some smart person here might also
work with the PI.

I am trying to build a package of C routines that I
have built and maintained for many years. The problem
is that the libs required by the programs have, apparently,
been re-written for the Debian version that runs on the
PI 5. The compile/link command that has worked for
gcc and libs up to Slack 15 is:

magic:magic.o eigen.o fft.o order.o xplot.o best.o minv.o utils.o xtfuncs.o mygetline.o mymouse.o
gcc -o/root/bin/magic -Xlinker -Map=/ram/MAP.map -lm -L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm \
magic.o eigen.o fft.o order.o xplot.o minv.o best.o utils.o xtfuncs.o mygetline.o mymouse.o

And similar lines for the rest of the Makefile.

As you can see, the package is a lot of mathematical routines. The
problem is that the math libraries have all be renamed, or something
else and none of the math functions compile. I get unresolved
errors for all the math functions log,exp,sin,cos..... as well
as anything using the Gnu math libraries.

I have used "dpkg -l" on the PI and I see that the libraries are
there, but the names are different and from the dpkg output
I can't find a makefile command that works.

The really surprising thing is that I got the PI5 about a month
ago, and I built the system from an image of March 15 2024.
I got everything in that system to work, including the math
package of interest. Then something choked and the system
would no longer boot. I tracked down the problem to something
that clobbered bash. Honestly it wasn't anything I did because
I left the system running for a couple of weeks, and when
I came back to it it was trashed. My guess is that some
"update" was the problem.

Starting with the same image, I rebuilt the system.
After starting, it does some updates and everything
but the math package works.

Perhaps someone in the Slack group also plays with the
PI and can give me some help. BTW, the main reason
for using the PI is that you get a free version of
Mathematica running on the PI.

Thanks for any help.
Henrik Carlqvist
2024-05-07 05:55:47 UTC
Permalink
Post by root
magic:magic.o eigen.o fft.o order.o xplot.o best.o minv.o utils.o
xtfuncs.o mygetline.o mymouse.o
gcc -o/root/bin/magic -Xlinker -Map=/ram/MAP.map -lm
-L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm \
magic.o eigen.o fft.o order.o xplot.o minv.o best.o utils.o
xtfuncs.o mygetline.o mymouse.o
The above is the linking step where your executable magic is linked by a
number of object files and some standard system libraries.
Post by root
The problem is that the math libraries have all be renamed, or something
else and none of the math functions compile. I get unresolved errors for
all the math functions log,exp,sin,cos..... as well as anything using
the Gnu math libraries.
As you say, sin, cos and other functions are expected to be in libm which
you should get linked with the switch -lm.

Are you sure that cos is missing from your standard math library? You
could check with a command like:

nm /usr/lib*/libm.so | grep " cos"

If you find cos in the library, my guess instead is that your command
line has failed. Could it be that the switch "-Map=/ram/MAP.map" somehow
hides the switch "-lm"?

Another problem which I have seen during the years is that some linkers
might be picky about the order of object files and libraries. They
require that object files and libraries come after object files and
libraries which call their functions. In your example you have all your
libraries before your object files, if you have such a linker those
object files will not find their functions in the libraries. If you don't
want to work out which files calls stuff in other files, one quick
workaround for such a situation would be to give all files twice:

gcc -o/root/bin/magic -Xlinker -Map=/ram/MAP.map \
-lm -L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm \
magic.o eigen.o fft.o order.o xplot.o minv.o best.o utils.o \
xtfuncs.o mygetline.o mymouse.o \
-lm -L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm \
magic.o eigen.o fft.o order.o xplot.o minv.o best.o utils.o \
xtfuncs.o mygetline.o mymouse.o

regards Henrik
root
2024-05-07 16:27:13 UTC
Permalink
Post by Henrik Carlqvist
Another problem which I have seen during the years is that some linkers
might be picky about the order of object files and libraries. They
require that object files and libraries come after object files and
libraries which call their functions. In your example you have all your
libraries before your object files, if you have such a linker those
object files will not find their functions in the libraries. If you don't
want to work out which files calls stuff in other files, one quick
gcc -o/root/bin/magic -Xlinker -Map=/ram/MAP.map \
-lm -L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm \
magic.o eigen.o fft.o order.o xplot.o minv.o best.o utils.o \
xtfuncs.o mygetline.o mymouse.o \
-lm -L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm \
magic.o eigen.o fft.o order.o xplot.o minv.o best.o utils.o \
xtfuncs.o mygetline.o mymouse.o
Thanks for responding Henrik. I tried your modification to
the Makefile and I got a lot of "multiple defininitions" in addition
to the other errors.

In order to track down my problem I tried a simple example:

/*
program to test math functions
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termio.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

#include <gsl/gsl_math.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>

extern gsl_rng * rgsl; /* global generator */
double gsl_sf_gamma();


int main(argc,argv)
int argc;
char *argv[];
{
double x,y;

x=atof(argv[1]);
y=exp(x);
printf("x=%g y=%g\n",x,y);

y=gsl_sf_gamma(x);
printf("x=%g y=%g\n",x,y);
exit(0);
}

I compiled and linked this with the same command as in my Makefile:

gcc trym.c -o/root/bin/trym -Xlinker -Map=/ram/MAP.map -lm -L/usr/lib64/gsl -lgsl -lgslcblas -rdynamic -ldl -lgpm

The test program compiled and ran perfectly.

Thanks again Henrik.

Loading...