0

I'm trying to compile this program but I keep getting this error in the report log

Undefined symbols for architecture x86_64:
  "Net::feedForward(std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _main in main.o
  "Net::backProp(std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _main in main.o
  "Net::getResults(std::__1::vector<int, std::__1::allocator<int> >&) const", 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 code is straight from a youtube tutorial I was trying to follow, here is the main.cpp code:

#include <iostream>
#include <vector>
#include "Net.h"


int main() {
    vector<int> topology;
    Net myNet(topology);
    //constructor needs to know # of layers it wants & # neurons per layer

    vector<int> inputVals;
    vector<int> targetVals;
    vector<int> resultVals;
    myNet.feedForward(inputVals);
    //feeds inputs to begin with
    myNet.backProp(targetVals);
    //pass in some array with goal state
    myNet.getResults(resultVals);

}

Net.h code:

#ifndef Net_hpp
#define Net_hpp

#include <stdio.h>
#include <vector>

using namespace std;

class Neuron{};
typedef vector<Neuron> Layer;

class Net{
public:
    Net(const vector<int> topology);
    void feedForward(const vector<int> &inputVals);
    void backProp(const vector<int> &targetVals);
    void getResults(vector<int> &resultVals) const;

private:
    vector<Layer> m_layers; //m_layers[layerNum][neuronNum]
};

#endif /* Net_hpp */

and Net.cpp code:

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

Net::Net(const vector<int> topology){
    int numLayers = topology.size();
    for(int layerNum = 0; layerNum < numLayers; ++layerNum){


    }
}

I really have no clue how to fix it, and other threads with similar-ish issues haven't helped either. If someone could please help me out I'd greatly appreciate it.

conejo
  • 31
  • 6
  • 1
    You never implemented `feedForward` and the other member functions mentioned in the error message. – walnut Sep 23 '19 at 06:45
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – walnut Sep 23 '19 at 06:46
  • Wow. I forgot I didn't include an empty { } body next to the member function declarations. Thank you @uneven_mark – conejo Sep 23 '19 at 07:04

0 Answers0