ios - 错误 : symbol 'xxx' is multiply defined

标签 ios linker metal

我在我的代码中添加了多个 Metal 着色器,现在我得到:

Error: symbol '<shader name>' is multiply defined
Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metallib failed with exit code 1

我不在任何地方包含 .metal 文件(XCode 负责编译本身)并且我无法将 inlinestatic 添加到函数,那有什么问题呢?

最佳答案

在头文件中定义函数也有问题。我以为我可以内联它们,但似乎我只能声明它们。

例如,我有这个头文件,

// ShaderMath.h
#pragma once
using namespace metal;
float4 conjugate(const float4 q);

float4 conjugate(const float4 q) {
  return float4( -q.xyz, q.w );
}

如果我在多个 Metal 文件中包含此 header ,我会收到“多重定义”错误。但是,如果我将定义移动到 .metal 文件,那么它就可以工作。头文件只是,

// ShaderMath.h
#pragma once
using namespace metal;
float4 conjugate(const float4 q);

和 Metal 锉,

// ShaderMath.metal
#include <metal_stdlib>
#include "ShaderMath.h"
using namespace metal;
float4 conjugate(const float4 q) {
  return float4( -q.xyz, q.w );
}

我希望这可以帮助其他遇到同样问题的人。

关于ios - 错误 : symbol 'xxx' is multiply defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31953680/

相关文章:

找不到 iOS Metal 默认库

ios - 未调用文件提供程序 iOS11 startProvidingItem

javascript - jquery 焦点功能在 iphone 中不起作用

ios - 无法使用动态内容调整 UIView 的大小

linux - 将符号链接(symbolic link)到 Linux 上的固定地址

c++ - 无法链接到 SQLite3 静态库

ios - Metal makeComputeCommandEncoder 断言失败

java - Mobile - Codename - 怎么比母语快?

c++ - 向 Code::Blocks 添加链接器选项

ios - Metal iOS 中的 mask