您能解释一下为什么我的示例中的AllToAll
函数未定义吗?我使用CMake生成一个libNeuralNetwork.a,以示例为例。
LayerFactory.hpp
#pragma once
#include "LayerModel.hpp"
#include "Layer.hpp"
namespace nn
{
extern internal::LayerModel AllToAll(int numberOfNeurons, activationFunction activation = sigmoid);
}
LayerFactory.cpp
#include "LayerFactory.hpp"
#include "AllToAll.hpp"
using namespace nn;
using namespace internal;
LayerModel AllToAll(int numberOfNeurons, activationFunction activation)
{
LayerModel model
{
allToAll,
activation,
numberOfNeurons
};
return model;
}
神经网络
#pragma once
#include "layer/LayerModel.hpp"
#include "layer/LayerFactory.hpp"
namespace nn
{
class NeuralNetwork
{
public:
NeuralNetwork(int numberOfInputs, std::vector<internal::LayerModel> models);
//...
};
}
范例.cpp
#include "../src/neural_network/NeuralNetwork.hpp"
using namespace nn;
int example1()
{
NeuralNetwork neuralNetwork(3, {AllToAll(5), AllToAll(2)});
}
错误信息:
CMakeFiles/UnitTests.out.dir/ExamplesTest.cpp.o: In function `example1()':
ExamplesTest.cpp:(.text+0x8b3): undefined reference to `nn::AllToAll(int, nn::activationFunction)'
最佳答案
您已在顶级 namespace 中声明了AllToAll
,并在nn
namespace 中对其进行了定义。
以下内容不会在 namespace 中声明该函数:
using namespace foo;
extern void Bar();
你需要:
namespace foo {
extern void Bar();
}
关于c++ - 未定义对使用CMake生成为lib .a的方法的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59579808/