Undefined link to `kill '

I developed an application for the ARM7 embedded system in C. Now I want to compile and link it with C ++ in order to use some C ++ functions. For this, I use mipsel-elf-g++ instead of mipsel-elf-gcc . I can compile my code with mipsel-elf-g++ successfully, but at the linking stage I get errors:

/opt/mipsel/lib/gcc/mipsel-elf/3.4.6/../../../../mipsel-elf/lib/libc.a(lib_a-abort.o): In the 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 the 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 for this problem and found that I had to implement my own _exit and kill functions, so I added these 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 the `_exit 'error is fixed, but the undefined reference to the` kill' error still exists.

What should I do to fix this problem?

+4
source share
2 answers

Try wrapping the kill function in extern "C" { … } . And, for clarity, I suggest not using the _DEFUN macro.

+2
source

I'm not sure, but the first thing I see is that the "kill" parameter has no type ...

But the only undefined reference errors I have ever received is error binding ... are there any libraries that you forgot to link to?

0
source

Source: https://habr.com/ru/post/1392198/


All Articles