I have been trying to link separate libraries that I've built from newlib to a pre-built package of ARM GCC 12, which I got from their developer site. I've rebuilt newlib using modified flags gotten from the file in ARM GCC 12.2.mpacbti-rel1-x86_64-arm-none-eabi-manifest.txt. Specifically I removed the --enable-newlib-mb flag as it causes a lot of extra build space to be generated. I have ran several builds of newlib and have verified that the newlib configuration flags being used do not affect the errors being produced.
Using the compilation flag '-nostdlib', which from my knowledge is necessary to use external libraries instead of the default ones, results in some undefined references to C library functions. Some of these include 'memcpy', 'memset' or 'malloc'.
The current linker flags I've used for this are:
-nostdlib -L[gcc path]/lib -lgcc -lc -lm
With the built newlib libraries being located in the [gcc-install]/lib directory. This currently causes the undefined references.
Edit: Compiler output contains undefined references to: 'memset', 'mktime' 'setvbuf', 'strlen', 'strcmp', 'memcpy', 'strftime', '__aeabi_dcmplt', '__aeabi_f2d', '__aeabi_dadd', '__aeabi_dmul, '__aeabi_d2ulz', 'memmove', 'modf', 'localtime_r', 'mallinfo', '_ctype_', 'gettimeofday', '_errno', 'malloc', and 'write'.
Using the flag
-nostdlibcaused linking errors due to the GCC not linking the startup file (as per KamilCuk's response). Omitting this flag and instead only using-Lto provide the newlib library path solved the undefined function references.Moreover, I had to spend some time resolving floating point ABI issues. The linker complained that my project's
.elffile was using hardfp floating point ABI operations while my libraries were using softfp. I provided the following path for newlib, which solved the issue (version 4.3.0):-L[path to newlib build]/arm-none-eabi/thumb/autofp/v7/fpu/newlib -lc