glfwInit fails inside library X11: The DISPLAY env

2019-08-24 21:53发布

I'm trying to make a small window in one of my functions for a .so and I've run into an issue that I can't understand why it would happen.

int __attribute__((constructor)) Init() {
    pthread_create(&startupThread, nullptr, InitFunc, nullptr);
}

static void ErrorCallbackf(int, const char* err_str) {
    FILE *outee = fopen("/tmp/errors.txt", "w");
    fprintf(outee, "GLFW Error: %s\n", err_str); fflush(outee);
}

void* InitFunc(void*) {
static GLFWwindow* InitWindow(FILE* Cout) {
    glfwSetErrorCallback(ErrorCallbackf);
    // Initialise GLFW
    if( !glfwInit() )
    {
        fprintf( Cout, "Failed to initialize GLFW\n" );
        getchar();
        return nullptr;
    }
}

For some reason when this library gets loaded up glfwInit errors with: X11: The DISPLAY environment variable is missing

标签: c++ linux
0条回答
登录 后发表回答