Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to `kill'

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?

like image 964
Mir Milad Hosseiny Avatar asked Oct 24 '22 11:10

Mir Milad Hosseiny


2 Answers

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

like image 149
Arkku Avatar answered Nov 04 '22 20:11

Arkku


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
like image 27
Turambar Avatar answered Nov 04 '22 19:11

Turambar