Question

Can't include raymath.h into my C++ raylib application

I am trying to include "raymath.h" into my C++ raylib project, but I can't seem to get it working, I'm getting a build error.

The way I'm trying to include raymath.h:

#include <iostream>
#include <string>
#include "raylib.h"

extern "C" {
    #include "raymath.h"
}

And I'm getting the following error: raylib-master\src\raymath.h(2552,34): error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax

From what I could understand so far, is that on line 2552 of raymath.h:

float scalex = Vector3Length((Vector3){ a, b, c });

the code is not valid in C++ syntax, but in C.

I assume I am trying to include raymath.h wrong.

I have my project in Microsoft Visual Studio.

I have also tried including raymath without extern "C" {...}, just like raylib.h, but it did not work that way either.

 3  78  3
1 Jan 1970

Solution

 0

You may need to convert all of that type of code in raymath.h to the following:

// Extract scale const float det = aA + bB + c*C;
const Vector3 v;
v.x = a; 
v.y = b;
v.z = c;
float scalex = Vector3Length(v);

That should get around the error you are having.

2024-07-02
Chimera