对使用 CMake 生成为 lib .a 的方法的未定义引用
undefined reference to method generated as lib .a with CMake
你能解释一下为什么我的函数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);
}
层工厂.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)'
您已在顶级命名空间中声明了AllToAll
,并在nn
命名空间中定义了它。
以下内容不会在命名空间中声明函数:
using namespace foo;
extern void Bar();
你需要:
namespace foo {
extern void Bar();
}
相关文章:
- 在C++中使用内联方法时出现未定义的符号错误
- 对结构方法的未定义引用
- 对使用 CMake 生成为 lib .a 的方法的未定义引用
- 在销毁期间从另一个线程调用对象上调用方法是否未定义行为?
- 对纯抽象类中方法的未定义引用
- G++ 编译器未为未定义的方法生成错误/警告
- 为什么虚拟方法生成对_sbrk的未定义引用?
- 对超类方法的未定义引用
- 对已定义方法的未定义引用
- Android JNI 未定义对错误 c++ 方法的引用
- C++类方法包含对静态变量的未定义引用
- 在 cpp 正文中声明方法时未定义的符号
- 对另一个静态库中静态库方法的未定义引用
- 解决方法:未定义对"class::function"的引用
- 对于我的 ComplexNumber 中的某些方法,我得到了一个奇怪的未定义错误引用.cpp,不过我对模板很陌生
- 如果未使用方法本身,则忽略方法中的未定义符号
- 标准::字符串::空的未定义符号错误;Mac OS High Sierra 上的 c++ 标准方法链接错误
- 链接webrtc本机时出错,因为未定义对具有std::string的方法的引用
- 编译器说模板类中的方法未定义,除非我将其设为虚拟
- .cpp文件中模板类的非模板方法-未定义的引用