Page 1 of 1

linking with `round` for the pyboard

Posted: Thu Mar 19, 2020 10:46 am
by v923z
Hi all,

I have attempted to add the around function to ulab, and to that end, I call math's round as MICROPY_FLOAT_C_FUN(round) https://github.com/v923z/micropython-ul ... ise.c#L156 . This works on the unix port, but I can't compile for the pyboard, and get a linker error

Code: Select all

LINK build-PYBV11/firmware.elf
arm-none-eabi-ld: build-PYBV11/code/vectorise.o: in function `vectorise_around':
vectorise.c:(.text.vectorise_around+0x76): undefined reference to `roundf'
make: *** [Makefile:582: build-PYBV11/firmware.elf] Error 1
I have tried to add the linker flag in the Makefile, but that doesn't help at all. What bugs me is the fact that the other math functions can be linked, and I don't see, why roundf should be any more special.

Can someone shed some light on the problem?

Thanks,
Zoltán

Re: linking with `round` for the pyboard

Posted: Fri Mar 20, 2020 2:54 am
by jimmo
v923z wrote:
Thu Mar 19, 2020 10:46 am
I have tried to add the linker flag in the Makefile, but that doesn't help at all.
Can you explain what you mean by that... you should just need to add roundf.c to SRC_LIBM. (It seems to work for me).

Re: linking with `round` for the pyboard

Posted: Fri Mar 20, 2020 8:16 am
by v923z
jimmo wrote:
Fri Mar 20, 2020 2:54 am
v923z wrote:
Thu Mar 19, 2020 10:46 am
I have tried to add the linker flag in the Makefile, but that doesn't help at all.
Can you explain what you mean by that...
I added -lm to the linker flags.
you should just need to add roundf.c to SRC_LIBM. (It seems to work for me).
That solved it, thanks!

However, I haven't yet found a way of appending to a make variable on the command line. All solutions I have seen so far rely on changing the makefile itself, which I want to avoid. I hope it doesn't sound selfish, but I would really like ulab to be a standard, drop-in user module that one can compile without having to change anything in micropython.

Re: linking with `round` for the pyboard

Posted: Fri Mar 20, 2020 8:50 am
by jimmo
v923z wrote:
Fri Mar 20, 2020 8:16 am
I added -lm to the linker flags.
That tells the compiler to use its libm.a -- which we don't want.
v923z wrote:
Fri Mar 20, 2020 8:16 am
That solved it, thanks!
Great, I think you should send a PR to add this unconditionally. (The linker will throw it away if it's unused).
v923z wrote:
Fri Mar 20, 2020 8:16 am
I hope it doesn't sound selfish, but I would really like ulab to be a standard, drop-in user module that one can compile without having to change anything in micropython.
Not at all, it's exactly the right thing to aim for.

In this case I think the limitation is as described above - MicroPython should have had this in the sources list anyway. Setting a linker flag isn't what you want.

But yes, if you did need to set a linker flag from your C module makefile, then if that's not currently possible then it would be worth sending a PR to make it possible. I will take a look later.

Re: linking with `round` for the pyboard

Posted: Mon Mar 23, 2020 9:42 am
by v923z
jimmo wrote:
Fri Mar 20, 2020 8:50 am
But yes, if you did need to set a linker flag from your C module makefile, then if that's not currently possible then it would be worth sending a PR to make it possible. I will take a look later.
OK, I'll update the makefiles, and send a PR.

Re: linking with `round` for the pyboard

Posted: Tue Mar 24, 2020 7:19 am
by v923z
Jim, as requested, I have modified the makefiles, and issued a PR: https://github.com/micropython/micropython/pull/5789