The program is structured as follows:
main.c:
#include <stdio.h>
#include "../include/test.h"
int main(){
moo();
return 0;
}
test.c:
#include <stdio.h>
#include "../include/test.h"
void moo(){
printf("moo\n");
}
test.h:
#ifndef MOO_HEADER
#define MOO_HEADER
void moo();
#endif
The directory structure is as follows: 1)proj2 1.1)include 1.1.1)test.h 1.2)src 1.2.1)main.c 1.2.2)test.c
The command that is executed on running using code runner is:
cd "/home/saumya/Desktop/cProj/proj2/src/" && clang-12 main.c -o main && "/home/saumya/Desktop/cProj/proj2/src/"main
The error message looks like:
/usr/bin/ld: /tmp/main-6d60a6.o: in function `main':
main.c:(.text+0x12): undefined reference to `moo'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Not sure what I am doing wrong here. Would be grateful for any inputs.
The code works completely fine if instead of including the test.h header file I directly include the test.c file but if I am not wrong that is not the best method to use #include while coding.