gpt4 book ai didi

c - ARM GCC 中对 posix_memalign 的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 20:42:10 26 4
gpt4 key购买 nike

我正在使用(STM32F407VG-Discovey 板)和编译器“gcc-arm-none-eabi-7-2017-q4-major”(arm-none-eabi-gcc),并且我正在尝试实现“google 项目 flatbuffers” ”。这需要运行时库 malloc.h 以及堆内存。

我在 ARM 处理器上打开堆内存,并使用 include 和调用 malloc 函数的基本操作对其进行测试。一切正常。

现在我包含了 google flatbuffers 头文件,现在我收到错误“对‘posix_memalign’的 undefined reference ”。我的链接器找不到这个函数。它没有找到,但应该已经有了 posix_memalign in stdlib.h错误看起来像这样:

enter image description here

在我的 CMake 文件中,我已将标志设置为

SET(CMAKE_C_FLAGS "-mthumb -fno-builtin -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wall -std=gnu11 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -lc -lrdimon" CACHE INTERNAL "c compiler flags")

我还发现,如果我不使用标志 -lc 和 -lrdimo,将会有对 _write()、_read()、_sbrk、_exit .....的 undefined reference

解释为什么这不重复:我知道使用 CMake 添加链接器库,您可以执行命令 target_link_libraries()。这里的问题是,出于重要原因,我的类轮找不到 posix_memalign 函数。但它会找到其他函数,如 malloc、alloc、free……它们都在“stdlib.h”中。

最佳答案

尝试使用

#include <malloc.h>
void* p;
p = memalign(alignment, size);

而不是

    posix_memalign(&p, alignment, size);

另请参阅 link

关于c - ARM GCC 中对 posix_memalign 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53614538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com