[linux]undefined reference to `

linux程序

#include

#include

#include

int count=0;

void ctrl_c_count(int);

int main(void)

{

int c;

void (*old_handler)(int);

old_handler=signal(SIGINT,ctrl_c_count);

while((c=getchar()!=’ ‘))

;

printf("Ctrl_C count=%d ",count);

signal(SIGINT,old_handler);

}

void ctrl_c_count(int i)

{

printf("Ctrl_C ");

count++;

}

这个程序的功能是研究signal函数的应用.

signal 函数是用于设置信号量的处理函数为自定义的。

SIGINT是用户在终端上按下ctrl+c的而产生信号量

它的系统默认的处理函数为终止正运行的进程

现在把它改成按ctrl+c后,是全局变量count加1的操作

当用户在终端输入回车后该进程结束。

且又把SIGINT的处理函数为默认的。

当把上述程序保存为test.cpp时,注意这里保存的文件格式为cpp

利用gcc -o test test.cpp

产生如下错误

/tmp/ccGsoxH2.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0′

解决方法用 gcc -o test test.cpp -lstdc++

为什么会出现这个错误:是因为你用gcc编译.cpp文件.按系统默认.cpp文件是c++的文件格式

另一个方法是用g++ -o test test .cpp 也是可以的

还有一种方法

如果你是把文件保存为.c格式,反正里面全是c的代码

http://heyunhuan513.blog.163.com/blog/static/16020422009923992100/

怕走崎岖路,莫想登高峰。

[linux]undefined reference to `

相关文章:

你感兴趣的文章:

标签云: