将Visual Studio/VisualGDB构建系统移植到CMake/GCC

将Visual Studio/VisualGDB构建系统移植到CMake/GCC,cmake,arm,cross-compiling,libc,visualgdb,Cmake,Arm,Cross Compiling,Libc,Visualgdb,我一直致力于将一个项目从运行在Win10机器上的Visual Studio/VisualGDB移植到运行在Ubuntu 16.04上的CMake/GCC构建系统。整个构建最终将在Cortex-M4上运行 在这个过程中,我遇到了一个链接器问题,其中libc中有几个引用未定义 {...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-sbrkr.o): In function `_sbrk_r': sbrkr.c:(

我一直致力于将一个项目从运行在Win10机器上的Visual Studio/VisualGDB移植到运行在Ubuntu 16.04上的CMake/GCC构建系统。整个构建最终将在Cortex-M4上运行

在这个过程中,我遇到了一个链接器问题,其中libc中有几个引用未定义

{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-sbrkr.o): In function `_sbrk_r':
    sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-writer.o): In function `_write_r':
    writer.c:(.text._write_r+0x10): undefined reference to `_write'
{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-closer.o): In function `_close_r':
    closer.c:(.text._close_r+0xc): undefined reference to `_close'
{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-fstatr.o): In function `_fstat_r':
    fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-isattyr.o): In function `_isatty_r':
    isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-lseekr.o): In function `_lseek_r':
    lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
{...}/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-readr.o): In function `_read_r':
    readr.c:(.text._read_r+0x10): undefined reference to `_read'
我使用以下标志:

CFLAGS:

-fdata-sections -ffunction-sections -std=gnu99 -mabi=aapcs -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASM_标志:

-x assembler-with-cpp
LDFLAGS:

-static -Wl,--gc-sections -mabi=aapcs -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lc -lnosys
这些标志来自原始VisualGDB构建,该构建没有任何问题

我发现,当使用
--specs=nosys.specs
而不是
nano.specs
时,构建完成,但在目标上运行时,在
\ulibc\u init\u array()中的某个地方触发了硬故障

我怀疑这是由于
nano.specs
nosys.specs
之间的差异造成的,但是由于上面提到的链接器问题,我无法验证这一点。我尝试了组合
--specs=nono.specs--specs=nosys.specs-lc-lnosys
,但没有任何运气


有人知道为什么它与VisualGDB而不是与CMake/GCC一起工作吗?据我所知,VisualGDB仍在使用吗?这当然是我使用的同一个工具链(经过测试的版本4.9.3和6.3.1)

我只是通过安装以下软件包来使用Ubuntu附带的交叉编译工具链:
gcc-arm-linux-gnueabihf-g++-arm-linux-gnueabihf-libc6-dev-armhf-cross-libgc1:armhf-libc6:armhf
。这些软件包用于裸机吗?我不认为现在切换到linux编译器会对我有所帮助。不,主板运行linux。