Undefined reference to `main' and _sbrk - startup code in own static library
<p>I'm working on a Cortex-M4 (STM32F4-Discovery board), using the GNU ARM Embedded toolchain (gcc-arm-none-eabi-5_4-2016q2). The hardware dependent part of my code (HAL-lib, CMSIS, startup etc.) is built in a static library, which I try to link to my application code. My application code contains a <code>main</code> symbol and my library contains a <code>_sbrk</code> symbol. These are the error messages:</p>

<pre><code>engine_control/source/os/release/libkosmos-arm-stm32f4-discovery.a(_startup.o): In function `_start': 
_startup.c:(.after_vectors+0x9a): undefined reference to `main'
</code></pre>

<p>and:</p>

<pre><code>/opt/gcc-arm-none-eabi-5_4-2016q2/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-sbrkr.o): In function `_sbrk_r': 
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
</code></pre>

<p>I assume there is something wrong with my link order. Here is my link command:</p>

<pre><code>arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Werror -Wunused -Wuninitialized -Wall -Wextra -Wmissing-declarations -Wconversion -Wpointer-arith -Wpadded -Wshadow -Wlogical-op -Waggregate-return -Wfloat-equal -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"config/linker" --specs=nano.specs -L/home/tkl/git/engine_control/source/os/release -Wl,-Map,"/home/tkl/git/engine_control/release/map/arm/release/.map" -lkosmos-arm-stm32f4-discovery -o "/home/tkl/git/engine_control/release/execute/arm/release/.elf" 
</code></pre>

<p>What am I doing wrong?</p>