herteladrian herteladrian - 1 month ago 10
C++ Question

Undefined symbols for architecture x86_64 using C++ classes

I've read the other questions on this topic but still haven't figured out how to fix my issue

Thank you in advance for your help!

My error is:


Undefined symbols for architecture x86_64:
"Record::Record(std::__1::vector, std::__1::allocator >, std::__1::allocator, std::__1::allocator > > >, double*)", referenced from:
_main in akh70P3ClassTester-946637.o
ld: symbol(s) not found for architecture x86_64


Record.h



#include <string>
#include <vector>

using namespace std;

class Record
{
public:
Record();
Record(vector<string> , double []);

private:
//some variables
};


Record.cpp



#include "Record.h"
#include <string>
#include <vector>

using namespace std;

Record::Record() {}

Record::Record(vector<string> inputs, double num_inputs[] )
{
//variables happens
}


Main.cpp



#include "Record.h"
#include <vector>

using namespace std;

int main() {

vector<string> inputs;

double num_inputs[] = {};

Record temp(inputs, num_inputs);

return 0;
}

Answer

You probably aren't including Report.cpp in your compilation, e.g. only doing g++ main.cpp -o main

Instead, compile your program by including the report files: g++ main.cpp report.cpp -o main