Embedding Micropython in a standalone C application (micropython/examples/embedding )
-
- Posts: 34
- Joined: Wed Aug 08, 2018 9:15 am
Embedding Micropython in a standalone C application (micropython/examples/embedding )
Hi everyone,
I'm trying to compile the
"micropython/examples/embedding" program.
After running the make command I get this error:
"error: unknown type name 'uintptr_t'.
Does anyone know how to solve it?
Enviroment:
PC: Ubuntu 16.04
MicroPython: $ git clone https://github.com/micropython/micropython.git
$ cd micropython && git submodule update --init
I'm trying to compile the
"micropython/examples/embedding" program.
After running the make command I get this error:
"error: unknown type name 'uintptr_t'.
Does anyone know how to solve it?
Enviroment:
PC: Ubuntu 16.04
MicroPython: $ git clone https://github.com/micropython/micropython.git
$ cd micropython && git submodule update --init
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
uintptr_t comes from stdint.h
I'm not sure why mphal.h doesn't include stdint.h -- it probably should, otherwise unix_mphal.c needs to. Could you send a PR?
I'm not sure why mphal.h doesn't include stdint.h -- it probably should, otherwise unix_mphal.c needs to. Could you send a PR?
-
- Posts: 34
- Joined: Wed Aug 08, 2018 9:15 am
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Sorry for the ignorance: what is a PR? What should I do?
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
PR = Pull request. So you can get this fixed permanently.
But to solve the problem you just need to add
to the top of mphal.h
But to solve the problem you just need to add
Code: Select all
#include <stdint.h>
-
- Posts: 34
- Joined: Wed Aug 08, 2018 9:15 am
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Thank you very much Jimmo,
I added #include <stdint.h> to the top of micropython/py/mphal.h and
the old error is disappear but now there is this one:
In file included from ../../py/mphal.h:35:0,
from ../../py/mpprint.c:33:
../../ports/unix/mphalport.h: In function ‘mp_hal_delay_ms’:
../../ports/unix/mphalport.h:52:52: error: implicit declaration of function ‘usleep’ [-Werror=implicit-function-declaration]
static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
^
cc1: all warnings being treated as errors
../../py/mkrules.mk:47: recipe for target 'build/py/mpprint.o' failed
Any suggestions ?
I added #include <stdint.h> to the top of micropython/py/mphal.h and
the old error is disappear but now there is this one:
In file included from ../../py/mphal.h:35:0,
from ../../py/mpprint.c:33:
../../ports/unix/mphalport.h: In function ‘mp_hal_delay_ms’:
../../ports/unix/mphalport.h:52:52: error: implicit declaration of function ‘usleep’ [-Werror=implicit-function-declaration]
static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
^
cc1: all warnings being treated as errors
../../py/mkrules.mk:47: recipe for target 'build/py/mpprint.o' failed
Any suggestions ?
-
- Posts: 34
- Joined: Wed Aug 08, 2018 9:15 am
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Jimmo,
I resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
Now is all ok: the program is compiled.
By thre way, how I do make the 'Pull request' ?
'Pull request' tab --> New pull request ( green tab ) -->
and then ? ( I can't make a small branch to use them for pull rquest )
I resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
Now is all ok: the program is compiled.
By thre way, how I do make the 'Pull request' ?
'Pull request' tab --> New pull request ( green tab ) -->
and then ? ( I can't make a small branch to use them for pull rquest )
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
I don't know why this solved your problem...? usleep() is in unistd.h, which is already included in mphal.h. When I build examples/embedded, I did see the same problem with stdint.h, but I don't see this problem.ales.coppelli wrote: ↑Thu Aug 08, 2019 10:19 amI resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
The usual way is to:ales.coppelli wrote: ↑Thu Aug 08, 2019 10:19 amBy thre way, how I do make the 'Pull request' ?
'Pull request' tab --> New pull request ( green tab ) -->
and then ? ( I can't make a small branch to use them for pull rquest )
1. Fork micropython/micropython in your own github account
2. Add your fork as a remote to your local git repo on your PC
3. Make the changes in a branch, push it to your github fork
4. Make a pull request from your branch.
-
- Posts: 34
- Joined: Wed Aug 08, 2018 9:15 am
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
jimmo wrote: ↑Thu Aug 08, 2019 11:19 amI don't know why this solved your problem...? usleep() is in unistd.h, which is already included in mphal.h. When I build examples/embedded, I did see the same problem with stdint.h, but I don't see this problem.ales.coppelli wrote: ↑Thu Aug 08, 2019 10:19 amI resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
Try this: in your 'Makefile.uplib' change the CFLAGS option from "-std=gnu99" to "-std=c99".
You should to have my second issue.
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Ah I misunderstood what you were saying before. Why do you need to change it from gnu99 to c99? Are you compiling with something that isn't gcc? If there's a specific reason to use c99 for your code, could you compile libmicropython with gnu99 and your code with c99 (although i think that's exactly what the demo does).ales.coppelli wrote: ↑Fri Aug 09, 2019 12:55 pmTry this: in your 'Makefile.uplib' change the CFLAGS option from "-std=gnu99" to "-std=c99".
You should to have my second issue.
https://stackoverflow.com/a/55860859 has a great explanation of why this doesn't work (summary: usleep is deprecated, you can add -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L to Makefile.upylib to work around it).
But you're going to run into other problems using std=c99 for building libmicropyhton -- e.g. inline assembler.
-
- Posts: 34
- Joined: Wed Aug 08, 2018 9:15 am
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
jimmo wrote: ↑Fri Aug 09, 2019 1:38 pmAh I misunderstood what you were saying before. Why do you need to change it from gnu99 to c99? Are you compiling with something that isn't gcc? If there's a specific reason to use c99 for your code, could you compile libmicropython with gnu99 and your code with c99 (although i think that's exactly what the demo does).ales.coppelli wrote: ↑Fri Aug 09, 2019 12:55 pmTry this: in your 'Makefile.uplib' change the CFLAGS option from "-std=gnu99" to "-std=c99".
You should to have my second issue.
https://stackoverflow.com/a/55860859 has a great explanation of why this doesn't work (summary: usleep is deprecated, you can add -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L to Makefile.upylib to work around it).
But you're going to run into other problems using std=c99 for building libmicropyhton -- e.g. inline assembler.
Yes, you are right: for my ignorance ( to try resolve my problem ) I changed that option ( gnu99 to c99 ) without fully understanding the consequences. thank you very much for your patience ( and for my bad English )