Undefined reference to `kill'

2020-04-08 14:24发布

问题:

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 tokill'`

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?

回答1:

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



回答2:

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

But the only undefined reference errors I ever got were linking errors... so are there any libraries you forgot to link to?