fogleman / Craft

A simple Minecraft clone written in C using modern OpenGL (shaders).
http://www.michaelfogleman.com/craft/
MIT License
10.39k stars 1.39k forks source link

Build failing M_PI #167

Closed seemsindie closed 8 years ago

seemsindie commented 8 years ago

Hello, i am getting this error when running make:

/home/ivan/Projects/Private/Craft/deps/glfw/examples/boing.c: In function ‘deg2rad’:
/home/ivan/Projects/Private/Craft/deps/glfw/examples/boing.c:129:28: error: ‘M_PI’ undeclared (first use in this function)
    return deg / 360 * (2 * M_PI);
                            ^

I am using arch linux, i have cmake, make, glfw, tried to install other deps... Any idea why is failing?

telpalbrox commented 8 years ago

Same here, using Ubuntu 14.04 with all dependencies installed.

etamme commented 8 years ago

same here again - ubuntu 14.04

fogleman commented 8 years ago

Why don't one of you put this in an appropriate place and submit a pull request?

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
etamme commented 8 years ago

it looks like its a c99 thing, i think adding gcc -lm will fix it .. testing it now

etamme commented 8 years ago

yeah POSIX doesnt include M_PI, we need a #define _GNU_SOURCE added to the files that need M_PI. I'll see if i can get a PR together

fogleman commented 8 years ago

I see this in the GLFW files that use M_PI, probably an appropriate place to add another...

#if defined(_MSC_VER)
 // Make MS math.h define M_PI
 #define _USE_MATH_DEFINES
#endif
etamme commented 8 years ago

yeah im basically changing that to `

if defined(_MSC_VER)

// Make MS math.h define M_PI

define _USE_MATH_DEFINES

elif GNUC

define _GNU_SOURCE

endif

`

edit: ...sorry i cant get github to format the code properly with linebreaks