0

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. Cheers!

David Ranieri
  • 39,972
  • 7
  • 52
  • 94
user287474
  • 325
  • 1
  • 5
  • 19

1 Answers1

1

You need to link function.c into your binary:

gcc -Wall -Werror -Iinclude src/main.c src/function.c
NPE
  • 486,780
  • 108
  • 951
  • 1,012