libdragon icon indicating copy to clipboard operation
libdragon copied to clipboard

Linking to the math library

Open joeldipops opened this issue 5 years ago • 6 comments

I'm still getting my head around makefiles and linkers, but I ran into a problem using <math.h> functions.

Because I didn't know what I was doing with the makefile, I adapted mine from one of the examples which contained this line. LINK_FLAGS = -L$(ROOTDIR)/mips64-elf/lib -ldragon -lc -lm -ldragonsys -Tn64ld.x

Everything worked fine for a long time until I tried to use the pow function and I got this build error (repeated five times)

[...]/n64inst/mips64-elf/lib/libm.a(lib_a-w_pow.o): In function 'pow': (.text+0x318): undefined reference to '__errno'

I swapped -lc and -lm in that LINK_FLAGS line and it now builds, so this might be something libdragon needs to change as well. Or there was a better solution and I've shot myself in the foot for something down the line.

joeldipops avatar May 06 '19 04:05 joeldipops

I think it is safe to swap all of them.

anacierdem avatar May 07 '19 20:05 anacierdem

Since everything is static libraries, I surround the libs with --start-group and --end-group.

clbr avatar Jul 22 '19 17:07 clbr

@clbr Yeah, it seems to be the correct solution.

anacierdem avatar Nov 03 '19 09:11 anacierdem

We didn’t take any action yet, if it is ok with @joeldipops we can close it.

anacierdem avatar Jun 10 '20 21:06 anacierdem

It's not a problem for me any more so I don't mind if it's closed.

joeldipops avatar Jun 10 '20 22:06 joeldipops

Let's wait until we implement --start-group and --end-group into the makefiles.

anacierdem avatar Jun 12 '20 07:06 anacierdem

I think we can close it. math.h works perfectly with through the n64.mk build system. Before n64.mk there wasn't really a standard solutions, so people will have to fix their own makefile for this (or switch to n64.mk). There's not really much we can do about that in libdragon itself.

rasky avatar Nov 20 '22 10:11 rasky