user287474 user287474 - 1 year ago 114
C Question

undefined reference to 'funtion_name'

im having trouble understanding how to get the code in my src folder as shown below to run the header file in the include folder.

enter image description here

Include contains a functions.h file, and src contains a functions.c file as well as my main.c

The main contains a "#include "functions.h" ", and a reference to a function declared in function.h and function.c

When i'm in the main directory, to compile everything, I run the following:

gcc -Wall -Werror -Iinclude src/main.c

But I get this back in the terminal:

/tmp/ccHmaM4g.o: In function `main':
main.c:(.text+0x78): undefined reference to `sum'
collect2: error: ld returned 1 exit status

I am fairly new to linux, please tell me what I'm doing wrong.

Answer Source

You need to link function.c into your binary:

gcc -Wall -Werror -Iinclude src/main.c src/function.c
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download