I am writing a simple C program that changes the value of a data structure to 100.
#include"node.h"
#include <stdio.h>
int main() {
simpleObject object1;
object1.x = 200;
updateLocation(&object1);
printf("%d", object1.x);
}
It holds 2 other files, the header file named "node" and the source file also named "node".
"node.h"
typedef struct {
float x;
float y;
float z;
float mass;
} simpleObject;
void updateLocation(simpleObject* initObject);
"node.c"
#include "node.h"
void updateLocation(simpleObject* initObject) {
initObject -> x = 100;
}
When the file was compiled, I was given this error:
undefined reference to `updateLocation(simpleObject*)' collect2.exe: error: ld returned 1 exit status
I am completely confused as to why the updateLocation function is not defined, even though it is defined within "node.c".
When the code from "node.c" was deleted and placed in "node.h" in place of the declaration, it worked, but printed out 0.
What is occuring within my code?