Can't Link C++ sample without semi-hosting

Asked by Walter Esling

I downloaded version 4_7-2012q4 and was trying out the samples. I can compile and link the cpp example using semi-hosting, but if I change to compile and link with no semi-hosting, I get link errors.
Here is the command for semi-hosting:
arm-none-eabi-g++ cpp.cc ../../startup/startup_ARMCM0.S -mthumb -mcpu=cortex-m0 -D__NO_SYSTEM_INIT -Os -ffunction-sections -fdata-sections -fno-exceptions --specs=nano.specs --specs=rdimon.specs -lc -lc -lrdimon -L. -L../../ldscripts -T gcc.ld -Wl,--gc-sections -Wl,-Map=cpp.map -o cpp-CM0.axf

No problem.

arm-none-eabi-g++ cpp.cc ../../startup/startup_ARMCM0.S -mthumb -mcpu=cortex-m0 -D__NO_SYSTEM_INIT -Os -ffunction-sections -fdata-sections -fno-exceptions --specs=nano.specs -lc -lc -lnosys -L. -L../../ldscripts -T gcc.ld -Wl,--gc-sections -Wl,-Map=cpp.map -o cpp-CM0.axf

Linker Errors:
../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/armv6-m/libc_s.a(lib _a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/armv6-m/libc_s.a(lib _a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x2): undefined reference to `_getpid'
collect2: error: ld returned 1 exit status
make: *** [cpp-CM0.axf] Error 1

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
chengbin
Solved:
Last query:
Last reply:
Revision history for this message
Best chengbin (can-finner) said :
#1

You can try below command line:
 ./arm-none-eabi-g++ main.cc -mthumb -mcpu=cortex-m0 -Os -ffunction-sections -fdata-sections -fno-exceptions --specs=nano.specs -Wl,--gc-sections -Wl,-Map=cpp.map -o cpp-CM0.axf -lc -lstdc++ -lc -lnosys

This is a typical static library linking problem.
Generally this is caused by specs file used by g++ driver and different code arrangement of libnosys/librdimon and can be fixed by re-sorting libraries in command line. You may need to try several times with different permutations.

Hoping this helpful.

Revision history for this message
Walter Esling (walter-esling) said :
#2

Thanks chengbin, that solved my question.