aledalgrande
aledalgrande

Reputation: 5217

Error: symbol 'xxx' is multiply defined

I added multiple Metal shaders to my code and I now get:

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

I don't include .metal files anywhere (XCode takes care of the compilation itself) and I cannot add inline or static to the function, so what's wrong?

Upvotes: 4

Views: 916

Answers (3)

endavid
endavid

Reputation: 1943

There are also problems defining functions in a header file. I thought I could inline them, but it seems I can only declare them.

For instance, I had this header file,

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

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

If I include this header in more than one metal file, I get the "multiply defined" error. However, if I move the definition to a .metal file, then it works. The header file is just,

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

and the metal file,

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

I hope this helps other people stuck with this same problem.

Upvotes: 3

dcunited001
dcunited001

Reputation: 501

for me, this happens when i rename metal files. for some reason, there's some artifact that hangs around and i start seeing the duplicate symbols error on build. not sure if this is a bug or what, but the only way i can fix it is to rename the function.

Upvotes: 0

aledalgrande
aledalgrande

Reputation: 5217

Apparently if a shader function has exactly the same signature as another one in another file, it's seen as duplicate. I changed the name of the struct used for output and it linked.

Upvotes: 2

Related Questions