0

I'm attempting to setup my environment for Vulkan projects, and I'm running into issues with GLFW. I'm using VSCode and GCC on my system running Pop!_OS 22.04 LTS and I've installed GLFW using sudo apt install libglfw3 libglfw3-dev. I manually checked the install location, which is in /usr/include/GLFW, which I can confirm is included in my GCC include path.

I'm using this basic program to test that it installed correctly:

#include <GLFW/glfw3.h> // doesn't work with glfw3native.h either

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

However I get this error when attempting to compile:

g++ -pthread -o test main.cpp -lglfw -lGLU -lGL -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -lrt -ldl
main.cpp:1:10: fatal error: GLFW/glfw3.h: No such file or directory

I'm truly stumped. Here's what my GCC include path looks like:

ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "<stdin>"

And here's where GLFW is located:

~$ locate glfw3.h
/usr/include/GLFW/glfw3.h

If there's a blatantly obvious error with my configuration I'd love to know,

WI1110
  • 19
  • 2
  • Running that returns `-rw-r--r-- 1 root root 215555 Dec 8 2021 /usr/include/GLFW/glfw3.h` – WI1110 Mar 08 '23 at 06:33
  • Can't see the problem. What happens if you try a full path in your `#include` directive? – john Mar 08 '23 at 06:54
  • And what do you get on `ls -ld /usr/include/GLFW`? – john Mar 08 '23 at 06:55
  • @john That returns `drwxr-xr-x 2 root root 4096 Mar 5 18:14 /usr/include/GLFW`. And using the full path results in the same error. The problem is just that it can't find the GLFW file, even though it's installed in the correct place as far as I can tell. – WI1110 Mar 08 '23 at 07:02
  • @273k The first line of `main.cpp` is empty, just a formatting issue on my part, so technically `#include ` was on the second line. – WI1110 Mar 08 '23 at 07:03
  • It's very weird. Could you try `echo "#include " | gcc -xc++` and `echo "#include " | gcc -xc`. – 273K Mar 08 '23 at 07:11
  • Running both in the terminal returns `gcc: fatal error: no input files compilation terminated.` am I doing something wrong? – WI1110 Mar 08 '23 at 07:13
  • Does `cat /usr/include/GLFW/glfw3.h` work? – Alan Birtles Mar 08 '23 at 07:22
  • IDK. It should work as it's answered here https://stackoverflow.com/questions/47999819/pipeline-echo-to-gcc. Perhaps gcc is not an executable, but a command alias? I missed dash `-` at the end. Try it – 273K Mar 08 '23 at 07:22
  • @Alan Yup, that just prints the contents of the file, so I don't think the contents are the issue – WI1110 Mar 08 '23 at 07:25
  • Maybe try running the compiler under strace to see what gcc is actually trying to do and why it fails – Alan Birtles Mar 08 '23 at 07:27
  • `echo "#include " | gcc -xc++ -` – 273K Mar 08 '23 at 07:28
  • After running with strace I can't find anything which elaborates on the issue, just the same error saying it can't find GLFW. Maybe I should just build from source and include it in the project, rather than relying on whatever apt serves up to me. – WI1110 Mar 08 '23 at 07:41
  • @273k piping the include statement to gcc results in the same error, because gcc can't find the library in the first place. – WI1110 Mar 08 '23 at 07:43
  • To update this, when I copy `main.cpp` to my home folder it has no trouble including GLFW, however when I try to work on it from any other folder (Ex. `/home/{myusername}/Dev/vk_course/`) it can't include it. Still looking into why this is. – WI1110 Mar 10 '23 at 19:45
  • I found the cause, I had installed VSCode via Flatpak which for some reason was causing this error. I reinstalled using `sudo apt install code` and that fixed it. – WI1110 Mar 10 '23 at 19:53

0 Answers0