I have Ubuntu server (no GIU) version Ubuntu 16.04.3 LTS and an trying to install a program 'parsefsh-1.0-g231'.
I have downloaded the file and de-compressed it fine, now I need to compile it, so have tried 'make' but get the following error..
gcc -Wall -Wextra -g -std=gnu99 -DHAVE_VLOG -c -o projection.o projection.c
gcc -lm parsefsh.o fshfunc.o projection.o -o parsefsh
projection.o: In function `init_ellipsoid':
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:51: undefined reference to `pow'
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:51: undefined reference to `sqrt'
projection.o: In function `phi_rev_merc':
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:66: undefined reference to `sin'
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:67: undefined reference to `exp'
projection.o: In function `northing':
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:95: undefined reference to `tan'
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:95: undefined reference to `sin'
projection.o: In function `coord_diff':
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:111: undefined reference to `cos'
/home/ian/parsefshsrc/parsefsh-1.0-g231/projection.c:113: undefined reference to `atan2'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'parsefsh' failed
make: *** [parsefsh] Error 1
(there were more lines with different maths functions but I've removed them to shorten this message)
It looks to my No0b eyes an issue with the maths functions, I've done some Internet searching and a recommendation was found to try the following...
gcc projection.c -o projection.o -lm
but this gives me an error
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Now I'm stuck and can't really find any other answers on the Internet, can anyone help please?
Your research has led you along the right lines.
Examination of the software's Makefile shows that the rules for creating target
parsefish
areBecause there are no explicit actions for these rules, GNU Make uses its built-in rules. For the compile phase (
.c
to.o
) that'swhich works fine, given the Makefile's definitions
however in the link phase, the rule is of the form
Note that
$(LDFLAGS)
comes before the object code filen.o
, whereas$(LOADLIBES)
and$(LDLIBS)
come after. In the Makefile, onlyLDFLAGS
is defined:which puts
-lm
in the wrong place (references are resolved from left to right).The simplest solution is simply to change
LDFLAGS = -lm
toLDLIBS = -lm
.