D is trying to parse C and C++ inside strings
Johan
j at j.nl
Sat Mar 18 09:14:49 UTC 2023
On Saturday, 18 March 2023 at 03:00:46 UTC, Hipreme wrote:
> I'm writing Metal shaders right now on my engine and I got the
> following warning (I use warn as errors so this is giving me
> nuts as I'll need to refactor my code to hide that string)
>
>
> ```d
> string getCoolString()
> {
> return q{
> #include <metal_stdlib>
> #include <simd/simd.h>
> using namespace metal;
> };
> }
>
> void main()
> {
> writeln(getCoolString);
> }
> ```
>
> In the run.dlang, I get the following error:
>
> ```
> Error: d++ cannot find file path for header 'metal_stdlib'
> Error Program exited with code 1
> ```
Workaround: put the #include stuff in a normal string:
```
string getCoolString()
{
return
"#include <metal_stdlib>
#include <simd/simd.h>"
~ q{
using namespace metal;
};
}
void main()
{
import std.stdio;
writeln(getCoolString);
}
```
More information about the Digitalmars-d
mailing list