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

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

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


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: In function main’:
a.c:(.text+0xba): undefined reference todoSomething’
collect2: ld returned 1 exit status

The following headers are included:

#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?

What does this `ld` error (“undefined reference”) mean?

What does this error mean? /tmp/ccevEqoI.o: In function `main’: funcptr.c:(.text+0x61): undefined reference to `AddALL’ collect2: ld returned 1 exit status I’m trying to write a function which adds a

C (or C++?) Syntax: STRUCTTYPE varname = {0};

Normally one would declare/allocate a struct on the stack with: STRUCTTYPE varname; What does this syntax mean in C (or is this C++ only, or perhaps specific to VC++)? STRUCTTYPE varname = {0}; wher

What’s the difference between VARNAME_T and VARNAME_P in c/c++

I’m newbie in programming especially c and c++. I often saw VARNAME_P and VARNAME_T in c/c++. What are the difference between those two? Thanks in advance

What does ? in C mean?

What does a question mark (?) in C mean?

Whats the difference between float* varname and float *varname in classic c

What’s the difference between float* varname and float *varname in classic C?

What does lvalue reference type mean

Sec. 5.4/1 N3797 says: The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type and an xvalue if T is an rvalue reference to object type. What does it mean? I

In c# what does mean “< ? :”?

In c# what does mean < ? : in this string? return (a < b ? c: text) + ;

What does ?? mean in C#? [duplicate]

Possible Duplicate: What do two question marks together mean in C#? What does the ?? mean in this C# statement? int availableUnits = unitsInStock ?? 0;

what does ** mean in C

What does it mean when a object has 2 asterisks at the beginning? **variable

What does it mean to have an undefined reference to a static member?

I just wrote a class with some static data members, but now I am getting errors about undefined references. Why doesn’t this work? What am I doing wrong? (Note: This is meant to be an entry to Stac


You’re getting a linker error, so your extern is working (the compiler compiled a.c without a problem), but when it went to link the object files together at the end it couldn’t resolve your extern — void doSomething(int); wasn’t actually found anywhere. Did you mess up the extern? Make sure there’s actually a doSomething defined in b.c that takes an int and returns void, and make sure you remembered to include b.c in your file list (i.e. you’re doing something like gcc a.c b.c, not just gcc a.c)

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.

You need to compile and then link like this

gcc -c a.c
gcc -c b.c
gcc a.o b.o -o prog

An initial reaction to this would be to ask and ensure that the two object files are being linked together. This is done at the compile stage by compiling both files at the same time:

gcc -o programName a.c b.c

Or if you want to compile separately, it would be:

gcc -c a.c
gcc -c b.c
gcc -o programName a.o b.o

It is very bad style to define external interfaces in .c files. .

You should do this


    extern void doSomething (int    sig);


    void doSomething (int    sig)
       ... do stuff 


#include "a.h"
signal(SIGNAL, doSomething); 


make sure your doSomething function is not static.