Started using C++ a few days ago and having some trouble wrapping my head around header files. I have the following code divided into three files:
main.cpp
#include <iostream>
#include "config.h"
using namespace std;
int main() {
Config config;
config_init(config);
cout << config.skills << endl;
cout << config.abilities << endl;
return 0;
}
Then:
config.h
#ifndef TEST_CONFIG_H
#define TEST_CONFIG_H
struct Config {
float skills;
float abilities;
};
void config_init(Config& c);
#endif //TEST_CONFIG_H
and:
config.cpp
#include "config.h"
void config_init(Config& c) {
c.skills = 5;
c.abilities = 10;
}
Before subdividing the code in different files everything worked fine. However since I tried using header files I get the following error:
Undefined symbols for architecture x86_64:
"config_init(Config&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My suspicion is that there is something wrong in the declaration of the header file and the use of the reference but I don't know how to solve it.