Porting Visual Studio/VisualGDB build system to CMake/GCC

454 Views Asked by At

I have been working on porting a project from Visual Studio/VisualGDB running on a Win10 machine to a CMake/GCC build system running on Ubuntu 16.04. The complete build will eventually run on a Cortex-M4.

In this process, I encountered a linker issue where several references within libc are undefined

{...}/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'

I use the following flags:

CFLAGS:

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

ASM_FLAGS:

-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

These flags are from the original VisualGDB-build which build without any problems.

I found that when using --specs=nosys.specs instead of nano.specs, the build completes, but when running on target, a hard fault is triggered somewhere inside __libc_init_array().

My suspicions are that this is due to the difference between nano.specs and nosys.specs, however I am unable to verify this due to the linker issues mentioned above. I tried the combination <...> --specs=nono.specs --specs=nosys.specs -lc -lnosys without any luck.

Does anyone know why this works with VisualGDB and not with CMake/GCC? As far as I understand, VisualGDB still use arm-none-eabi? This is of course the same toolchain I am using (tested versions 4.9.3 and 6.3.1)

0

There are 0 best solutions below