undefined reference to `strtod' undefined reference to `strtol'

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Jack-123
Posts: 5
Joined: Wed Sep 05, 2018 2:29 am

undefined reference to `strtod' undefined reference to `strtol'

Post by Jack-123 » Wed Sep 05, 2018 2:39 am

Hello, I want to compile my own package into Micropython, but I am getting an error when compiling. The error message is:
undefined reference to strtod' undefined reference tostrtol'
How can I do? thank you.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by pythoncoder » Wed Sep 05, 2018 7:31 am

You'll need to provide a lot more information if anyone is to help you, notably your build command and the resultant traceback. Also what OS and compiler version are you using?
Peter Hinch
Index to my micropython libraries.

Jack-123
Posts: 5
Joined: Wed Sep 05, 2018 2:29 am

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by Jack-123 » Wed Sep 05, 2018 8:34 am

Thank you very much for your reply. I have a temporary solution: I wrote the `strtol' and `strtod' files myself, but I don't know what the pitfalls are.
Here is my basic situation:
1. Ubuntu arm-none-eabi-gcc-4.9.3
2, makefile In addition to adding my package file, the other did not make changes
3. Where the error occurred:
Unsigned char temp = 0;
temp = (unsigned char)(strtod(&g_cmd_b_p->cmd_buffer[g_cmd_b_p->cmd_queue_cnt][c_postion + 1], NULL)) ;
temp = (strtol(&g_cmd_b_p->cmd_buffer[g_cmd_b_p->cmd_queue_cnt][c_postion + 1],NULL,10));
4, the error message:
build-PYBV11/code/get_command.o: In function `checksum_dealwith_command':
get_command.c:(.text.checksum_dealwith_command+0x3e): undefined reference to `strtod'
build-PYBV11/code/get_command.o: In function `line_checksum_dealwith_command':
get_command.c:(.text.line_checksum_dealwith_command+0x34): undefined reference to `strtol'
Makefile:537: recipe for target 'build-PYBV11/firmware.elf' failed

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by pythoncoder » Thu Sep 06, 2018 7:10 am

These functions are part of the C standard library so I wonder if something is wrong with your gcc installation?

Disclaimer - I'm not a C guru. Hopefully one will pop up...
Peter Hinch
Index to my micropython libraries.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by jickster » Thu Sep 06, 2018 1:51 pm

What’s your linker command?


Sent from my iPhone using Tapatalk Pro

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by jickster » Thu Sep 06, 2018 4:09 pm

pythoncoder wrote:
Thu Sep 06, 2018 7:10 am
These functions are part of the C standard library so I wonder if something is wrong with your gcc installation?

Disclaimer - I'm not a C guru. Hopefully one will pop up...
You might have to include it in the linker command.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by dhylands » Thu Sep 06, 2018 4:17 pm

Micropython doesn't link against the C runtime library. It provides its own version of the very small number of functions that it needs.
https://github.com/micropython/micropyt ... r/lib/libc

Normally the python parser would convert strings into numbers. I found an example in ujson where it converts string version of numbers into numbers:
https://github.com/micropython/micropyt ... #L180-L201

Jack-123
Posts: 5
Joined: Wed Sep 05, 2018 2:29 am

Re: undefined reference to `strtod' undefined reference to `strtol'

Post by Jack-123 » Mon Sep 10, 2018 7:07 am

Thank you for your reply, I think I will still compile it with my own files.

Post Reply