Group Group Group Group Group Group Group Group Group

Metal with C library

Hi Caroline :slight_smile: Thank you for the elegant example of how to use Metal. I have a question that is somewhat off-topic to the game challenge, but it doesn’t really fit anywhere in the tutorial, which is excellent and has helped me understand Metal so much better.

I am trying to include a c library in the project you’ve built. The library compiles without errors, but as soon as I add it’s header to common.h, when I build, xcode tries to find c headers in the iPhone SDK, which of course breaks. If I try to include the library the same way in a new xCode 11 swift project without metal, it compiles without problems.

Can you point me in the right general direction? Why might Metal (which is written in c) have a conflict finding system c headers when another c lib is included?

I have more details here:

I am thoroughly at a loss for a resolution, any thoughts would be a great help :slight_smile: Thanks!!

MtDevice *device;
MtCommandQueue *cmdQueue;
MtRenderPipelineDescriptor *pipDesc;
MtLibrary *lib;
MtFunction *vertFunc, *fragFunc;
MtRenderPipelineState *pip;

device = mtCreateDevice();
lib = mtDefaultLibrary(device);
cmdQueue = mtCommandQueueCreate(device);
pipDesc = mtRenderDescCreate(MtPixelFormatBGRA8Unorm);

vertFunc = mtCreateFunc(lib, “vertexShader”);
fragFunc = mtCreateFunc(lib, “fragmentShader”);

mtSetFunc(pipDesc, vertFunc, MT_FUNC_VERT);
mtSetFunc(pipDesc, fragFunc, MT_FUNC_FRAG);

pip = mtRenderStateCreate(device, pipDesc);

@lewis-h thank you for the code fragment, but I’m not sure how it applies. Could you say more about why this is a solution to the problem? Thanks!