0

我正在尝试编译和运行我的 c++ 代码(这是我的代码的早期版本,只是为了检查它是否可以编译)。但是当我试图编译它时,我得到了错误:

Undefined symbols for architecture x86_64:
"Net::getResults(std::__1::vector<double, std::__1::allocator<double> > const&) const", referenced from:
      _main in nnet-53e1c0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我在这里包含了我的代码:

// nnet.cpp
//
//
//
#include <vector>
#include <iostream>
using namespace std;

class Neuron {};



//typer reference 
typedef vector<Neuron> Layer;





class Net
{
    public:
        Net(const vector<unsigned> &topology);
        void feedForward(const vector<double> &inputVals) {};
        void backProp(const vector<double> &argetVals) {};
        void getResults( const vector<double> &resultVals) const;


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


Net::Net(const vector<unsigned> &topology)
{
    unsigned numLayers = topology.size();
    for(unsigned layerNum =0; layerNum <numLayers; ++layerNum) {
        m_layers.push_back(Layer());

        // We have made a new Layer, now fill it ith neurons, and 
        // add a bias neuron to the layer
        for (unsigned neuronNum = 0; neuronNum <= topology[layerNum]; ++neuronNum) {

            m_layers.back().push_back(Neuron());
            cout <<"Made a new Neuron"<<endl;
        }
    }


}

int main()
{
    // e.g (3, 2, 1)
    vector <unsigned> topology; 
    topology.push_back(3);
    topology.push_back(2);
    topology.push_back(1);
    Net myNet(topology);

    vector <double> inputVals;
    myNet.feedForward(inputVals);

    vector <double> targetVals;
    myNet.backProp(targetVals);

    vector <double> resultVals;
    myNet.getResults(resultVals);
}

我不太确定这是怎么回事。一开始我怀疑这可能是向量动态库没有链接所以我想出了这个虚拟程序来测试它:

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    cout << "HW is done"<<endl;
    printf("Hello");
    return 0;
}

该程序会令人惊讶地编译并且不会抛出任何错误,但没有输出。没有印刷,什么都没有。

我正在使用 Mac,如果有人能够帮助我解决这个问题,我将不胜感激。谢谢!

4

0 回答 0