mac 上的编译问题错误:没有用于初始化'wavenet::WaveNet'的匹配构造函数



我在mac上遇到了编译问题,我正在尝试构建这个神经放大器建模器https://github.com/sdatkinson/iPlug2/tree/main/Examples/NAM在Apple M1 MBP macOS 12.6/Xcode 14.0 上

该存储库中的代码在Windows上有效,但在我的机器上我会收到以下错误:

Error: No matching constructor for initialization of 'wavenet::WaveNet'
In instantiation of function template specialization:
'std::make_unique<wavenet::WaveNet, std::vector<wavenet::LayerArrayParams> &, 
const float &, const bool &, nlohmann::basic_json<>, std::vector<float> &>'
In file included from /Users/username/Dev/iPlug2/Examples/NAM/get_dsp.cpp
note: wavenet.h note: candidate constructor not viable: expects an lvalue for 4th argument
note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided'

我不明白为什么它能在windows上工作,如果需要的话,我可以发布更多的代码,所有的文件都在存储库中,谢谢!

我根据自己的经验进行了快速猜测(不幸的是,我无法在Mac上进行测试(。

由于编译错误来自get_dsp.cpp,因此在尝试更改WaveNet类本身之前,我们应该先尝试在那里修复它。

make_unique调用在get_dsp.cpp的第83行中发出。

第87行是构造函数的第4个参数:

architecture == "CatWaveNet" ? config["parametric"] : nlohmann::json{}

我猜:之后默认构造的nlohmann::json是编译错误的根源。这将创建一个未命名的临时对象,该对象是一个右值。但是构造函数需要一个左值(对nlohmann::json的非常量引用(。为了解决这个问题,我们必须确保我们传递的东西可以作为左值,所以我们需要一个命名对象,比如:

auto my_json = architecture == "CatWaveNet" ? config["parametric"] : nlohmann::json{};

这必须放在第82行的返回语句之前;my_json";作为第87行中的构造函数参数。完整的更改块将如下所示:

auto my_json = architecture == "CatWaveNet" ? config["parametric"] : nlohmann::json{};
return std::make_unique<wavenet::WaveNet>(
layer_array_params,
head_scale,
with_head,
my_json,
params
);

它能解决问题吗?

因此,出于好奇,我最终让MacBook开始编译并重现您的错误。我对MacOS一点也不熟悉,这是我新雇主选择的系统。

还有一些额外的东西需要一些TLC:python 2.7已经被弃用,我相信你也发现了std::exception("message")是微软提供的另一个非标准实现。

然而,我现在可以放心地说,这确实是这个特定项目中最后一个不可移植的代码,并且nlohman::json参数可以通过再做一次更改来引用const。要消除您提到的最后一个错误,请修改第328行

for (nlohmann::json::iterator it = parametric.begin(); it != parametric.end(); ++it)

for (auto it = parametric.begin(); it != parametric.end(); ++it)

最新更新