What does the “undefined reference to varName” in C mean?

后端 未结 6 1590
粉色の甜心
粉色の甜心 2020-12-01 18:32

I have 2 files: a.c and b.c

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

signal(SIGU         


        
6条回答
  •  悲&欢浪女
    2020-12-01 19:07

    You need to link both a.o and b.o:

    gcc -o program a.c b.c
    

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

    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()).

    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.

    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.

提交回复
热议问题