问题描述
我用 C 语言开发了一个 ARM7 嵌入式系统的应用程序.现在我想用 C++ 编译和链接它,以便使用一些 C++ 特性.为此,我使用 mipsel-elf-g++
而不是 mipsel-elf-gcc
.我可以使用 mipsel-elf-g++
成功编译我的代码,但是在链接步骤中我得到了错误:
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):在函数```中止':/cygdrive/d/Files/cross/mips/newlib-1.15.0/newlib/libc/stdlib/abort.c:63:未定义引用_exit'`
/opt/mipsel/lib/gcc/mipsel-elf/3.4.6/../../../../mipsel-elf/lib/libc.a(lib_a-signalr.o):在函数```_kill_r':/cygdrive/d/Files/cross/mips/newlib-1.15.0/newlib/libc/reent/signalr.c:61:未定义引用kill'`
/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 返回 1 个退出状态
collect2: ld returned 1 exit status
我搜索了这个问题,发现我应该实现自己的_exit
和kill
函数,所以我将这段代码添加到我的项目中:
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;
}
通过添加这两个函数,修复了对 `_exit' 的未定义引用错误,但对 `kill' 错误的未定义引用仍然存在.
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?
推荐答案
尝试将 kill
函数包装在 extern "C" { ... }
中.而且,为了清楚起见,我建议不要使用 _DEFUN
宏.
Try wrapping the kill
function in extern "C" { … }
. And, for clarity, I suggest not using the _DEFUN
macro.
这篇关于对“kill"的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!