什么是"未定义的引用的varName"用C是什么意思? [英] What does the "undefined reference to varName" in C mean?

查看:177
本文介绍了什么是"未定义的引用的varName"用C是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文件:交流转换器 b.c

交流转换器我将信号发送到位于 b.c

In a.c I am sending a signal to a function located in b.c

signal(SIGUSR1,doSomething);

在交流转换器文件的顶部,我有:

On top of the a.c file, I have:

extern void doSomething (int    sig);

当我编译,但是,我得到一个错误:

When I compile, however, I get an error:

/tmp/ccCw9Yun.o:在功能主':结果
  。交流转换器:(文字+ 0xba):未定义引用
DoSomething的'结果
  collect2:劳工处返回1退出状态

/tmp/ccCw9Yun.o: In function main':
a.c:(.text+0xba): undefined reference to
doSomething'
collect2: ld returned 1 exit status

以下标头包括:

#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

我该如何解决这个问题?

How do I fix this?

推荐答案

您需要在两个 AO 博:

gcc -o program a.c b.c


如果你有一个的main()中的每一个文件,你不能将它们关联起来。


If you have a main() in each file, you cannot link them together.

不过,你的 AC 文件包含引用DoSomething的()并预计与源文件链接定义 DoSomething的()并没有定义在 AC定义(如的main())。

However, your a.c file contains a reference to doSomething() and expects to be linked with a source file that defines doSomething() and does not define any function that is defined in a.c (such as main()).

您不能调用进程B的函数从流程答:您不能将信号发送给一个函数;发送信号的过程,使用杀()系统调用。

You cannot call a function in Process B from Process A. You cannot send a signal to a function; you send signals to processes, using the kill() system call.

信号()函数指定哪些功能在当前的进程(程序)是怎么回事,当你的进程接收到信号处理的信号。

The signal() function specifies which function in your current process (program) is going to handle the signal when your process receives the signal.

您有一些严重的工作要做理解这是怎么回事工作 - ProgramA将如何知道该信号发送到该进程ID。在的code BC 将需要调用信号() DoSomething的作为信号处理程序。在的code交流转换器只是将信号发送到另一个进程。

You have some serious work to do understanding how this is going to work - how ProgramA is going to know which process ID to send the signal to. The code in b.c is going to need to call signal() with dosomething as the signal handler. The code in a.c is simply going to send the signal to the other process.

这篇关于什么是&QUOT;未定义的引用的varName&QUOT;用C是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆