编译时出错:来自“void*”的转换无效到“unsigned char*”

发布于 2024-12-24 18:20:39 字数 3207 浏览 1 评论 0原文

我正在对 Arduino mega 2560 进行编程。 我买了一个 tft LCD,为此我想使用 SD 卡,这样我就可以把我的照片放在上面。

我下载了这个库,但它给了我错误。

C:\Arduino\libraries\pff\pff.cpp: In function 'FRESULT pf_read(void*, short unsigned int, short unsigned int*)':
C:\Arduino\libraries\pff\pff.cpp:585: error: invalid conversion from 'void*' to 'unsigned char*'

问题出在我这里:

pff.cpp:

 FRESULT pf_read (
    void* buff,     /* Pointer to the read buffer (NULL:Forward data to the stream)*/
    WORD btr,       /* Number of bytes to read */
    WORD* br        /* Pointer to number of bytes read */
)

pff.h:

FRESULT pf_read (void*, WORD, WORD*);           /* Read data from the open file */

当我将其制作为 .c 文件时,它给了我更多错误,如下所示:

tft_menu.cpp.o: In function `open_root_dir()':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:594: undefined reference to `pf_opendir(_DIR_*, char const*)'
tft_menu.cpp.o: In function `mount_sd()':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:583: undefined reference to `disk_initialize()'
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:585: undefined reference to `pf_mount(_FATFS_*)'
tft_menu.cpp.o: In function `bitmap_show(char*)':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:472: undefined reference to `pf_open(char const*)'
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:476: undefined reference to `pf_read(void*, unsigned short, unsigned short*)'
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:518: undefined reference to `pf_read(void*, unsigned short, unsigned short*)'
tft_menu.cpp.o: In function `show_bitmap()':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:603: undefined reference to `pf_readdir(_DIR_*, _FILINFO_*)'

所以我认为它应该编译为 cpp。

编辑:

我发现我必须将 is 保存为 cpp 并且在程序中我必须编写 icktoofay 的状态

之后我遇到了一些错误,所以我转到第 585 行,如上所述并更改了

BYTE *rbuff = buff;

转换成

BYTE rbuff = (unsigned char) buff;

我发现我必须添加 mcc.h 才能摆脱“无法找到资源”的错误。

现在我收到这些错误:

C:\libraries\mmc/mmc.h: In function 'void init_spi()':
C:\libraries\mmc/mmc.h:21: error: 'PORTL' was not declared in this scope
C:\libraries\mmc/mmc.h:21: error: 'PORTL0' was not declared in this scope
C:\libraries\mmc/mmc.h:22: error: 'PORTB' was not declared in this scope
C:\libraries\mmc/mmc.h:22: error: 'PORTB2' was not declared in this scope
C:\libraries\mmc/mmc.h:22: error: 'PORTB1' was not declared in this scope
C:\libraries\mmc/mmc.h:23: error: 'DDRB' was not declared in this scope
C:\libraries\mmc/mmc.h:23: error: 'PORTB0' was not declared in this scope
C:\libraries\mmc/mmc.h:25: error: 'DDRL' was not declared in this scope
C:\libraries\mmc/mmc.h:27: error: 'SPCR' was not declared in this scope
C:\libraries\mmc/mmc.h:27: error: 'SPE' was not declared in this scope
C:\libraries\mmc/mmc.h:27: error: 'MSTR' was not declared in this scope
C:\libraries\mmc/mmc.h:28: error: 'SPSR' was not declared in this scope
C:\libraries\mmc/mmc.h:28: error: 'SPI2X' was not declared in this scope

我尝试在 mcc.h 之上添加 #include TFT_ARDUINO_MEGA.h 但仍然没有运气

Im programming an Arduino mega 2560.
And I bought an tft LCD and for that I want to use a SD card so I can put my pictures on it.

I downloaded this library but its giving me errors.

C:\Arduino\libraries\pff\pff.cpp: In function 'FRESULT pf_read(void*, short unsigned int, short unsigned int*)':
C:\Arduino\libraries\pff\pff.cpp:585: error: invalid conversion from 'void*' to 'unsigned char*'

The problem is imo here:

pff.cpp:

 FRESULT pf_read (
    void* buff,     /* Pointer to the read buffer (NULL:Forward data to the stream)*/
    WORD btr,       /* Number of bytes to read */
    WORD* br        /* Pointer to number of bytes read */
)

pff.h:

FRESULT pf_read (void*, WORD, WORD*);           /* Read data from the open file */

When I make it a .c file, it gives me more errors, like this one:

tft_menu.cpp.o: In function `open_root_dir()':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:594: undefined reference to `pf_opendir(_DIR_*, char const*)'
tft_menu.cpp.o: In function `mount_sd()':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:583: undefined reference to `disk_initialize()'
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:585: undefined reference to `pf_mount(_FATFS_*)'
tft_menu.cpp.o: In function `bitmap_show(char*)':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:472: undefined reference to `pf_open(char const*)'
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:476: undefined reference to `pf_read(void*, unsigned short, unsigned short*)'
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:518: undefined reference to `pf_read(void*, unsigned short, unsigned short*)'
tft_menu.cpp.o: In function `show_bitmap()':
C:\AppData\Local\Temp\build7310099894910129341.tmp/tft_menu.cpp:603: undefined reference to `pf_readdir(_DIR_*, _FILINFO_*)'

so I think it should be compiled as a cpp.

EDIT:

I found out that I have to save is as cpp and in the program I have to write what icktoofay states

After that I got some errors, so I went to the line 585, as stated above and changed

BYTE *rbuff = buff;

into

BYTE rbuff = (unsigned char) buff;

And I found out that I had to add mcc.h to get rid of the errors of the "couldnt find resources".

And now Im getting these errors:

C:\libraries\mmc/mmc.h: In function 'void init_spi()':
C:\libraries\mmc/mmc.h:21: error: 'PORTL' was not declared in this scope
C:\libraries\mmc/mmc.h:21: error: 'PORTL0' was not declared in this scope
C:\libraries\mmc/mmc.h:22: error: 'PORTB' was not declared in this scope
C:\libraries\mmc/mmc.h:22: error: 'PORTB2' was not declared in this scope
C:\libraries\mmc/mmc.h:22: error: 'PORTB1' was not declared in this scope
C:\libraries\mmc/mmc.h:23: error: 'DDRB' was not declared in this scope
C:\libraries\mmc/mmc.h:23: error: 'PORTB0' was not declared in this scope
C:\libraries\mmc/mmc.h:25: error: 'DDRL' was not declared in this scope
C:\libraries\mmc/mmc.h:27: error: 'SPCR' was not declared in this scope
C:\libraries\mmc/mmc.h:27: error: 'SPE' was not declared in this scope
C:\libraries\mmc/mmc.h:27: error: 'MSTR' was not declared in this scope
C:\libraries\mmc/mmc.h:28: error: 'SPSR' was not declared in this scope
C:\libraries\mmc/mmc.h:28: error: 'SPI2X' was not declared in this scope

Ive tried to add #include TFT_ARDUINO_MEGA.h on top of the mcc.h and still no luck

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不交电费瞎发啥光 2024-12-31 18:20:39

将其编译为 C 文件,但在使用它的文件中包含 pff.h,如下所示:

extern "C" {
#include <pff.h>
}

Compile it as a C file, but in the file that uses it, include pff.h like this:

extern "C" {
#include <pff.h>
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文