Search code examples
c++compilationglfw

Compiling GLFW manually "No supported window creation API selected"


I'm trying to compile GLFW by including GLFW sourcecode directly into my project (no lib or dll) and compile it.

Here is the simple example i did to try it :

#include <iostream>

#define _GLFW_WIN32

#include <glad/glad.h>
#include <GLFW\glfw3.h>

int main(int argc, const char *argv[])
{
    return 0;
}

All path defined in glfw3.h is correct, and as you can see I have defined macro _GLFW_WIN32 (According to https://www.glfw.org/docs/3.1/compile.html) However, when I compile, I got this error :

C:\GLFW\code\internal.h (194): fatal error C1189: #error: "No supported window creation API selected"

when looking at internal.h(line 183) :

#if defined(_GLFW_COCOA)
 #include "cocoa_platform.h"
#elif defined(_GLFW_WIN32)
 #include "win32_platform.h"
#elif defined(_GLFW_X11)
 #include "x11_platform.h"
#elif defined(_GLFW_WAYLAND)
 #include "wl_platform.h"
#elif defined(_GLFW_OSMESA)
 #include "null_platform.h"
#else
 #error "No supported window creation API selected"
#endif

Which makes no sense since I defined _GLFW_WIN32. Any ideas what am I doing wrong?


Solution

  • I found the problem, using #define macro is not enough since glfw will be compiled before my main code.

    The way I solve it is by using the

    -D _GLFW_WIN32

    symbol in the compilation command line