I developed an application for an ARM7 embedded system in C. Now I want to compile and link it with C++ in order to use some C++ features. To do this, I am using mipsel-elf-g++
instead of mipsel-elf-gcc
. I can compile my code with mipsel-elf-g++
successfully, but in linking step I get the errors:
/opt/mipsel/lib/gcc/mipsel-elf/3.4.6/../../../../mipsel-elf/lib/libc.a(lib_a-abort.o): In function
```abort': /cygdrive/d/Files/cross/mips/newlib-1.15.0/newlib/libc/stdlib/abort.c:63: undefined reference to
_exit'`/opt/mipsel/lib/gcc/mipsel-elf/3.4.6/../../../../mipsel-elf/lib/libc.a(lib_a-signalr.o): In function
```_kill_r': /cygdrive/d/Files/cross/mips/newlib-1.15.0/newlib/libc/reent/signalr.c:61: undefined reference to
kill'`collect2: ld returned 1 exit status
I searched about this issue and found that I should implement my own _exit
and kill
functions, so I added this codes to my project:
void _exit(int code)
{
while(1);
}
int _DEFUN (kill, (pid, sig), int pid _AND int sig)
{
if(pid == __MYPID)
_exit(sig);
return 0;
}
By adding these two functions, the undefined reference to `_exit' error is fixed, but the undefined reference to ``kill' error still exists.
What should I do to fix this issue?
Try wrapping the kill
function in extern "C" { … }
. And, for clarity, I suggest not using the _DEFUN
macro.
I know this is an old question, but I ran against the same problem and found a solution. Add these options to your linker:
-specs=nano.specs -specs=nosys.specs -lnosys
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With