Missing C++ Headers

I’m learning how to use OpenGL and SDL2 in C++, I hav already installed gcc and all the dependencies (SDL2 GL GLEW GLFW)

I’m using VSCode 1.84.2 and gcc/g++ are latest.

The problem is, I’m somehow missing the cstddef.h header which is needed by GLFW. I tried uninstalling and installing gcc but it did not fix anything. Not sure what’s up as I’m new to VSCode and local C++ development.

Line that causes errors:

#include <cstddef.h>

Errors throw by VSCode:

1: #include errors detected based on information provided by the configurationProvider setting. Squiggles are disabled for this translation unit (/home/samuel/VSCode Projects/GameTest5/main.cpp).
2: cannot open source file "cstddef.h"
3: cstddef.h: No such file or directory

I do not know if this will help in your situation but this helped one on the net.

The cstddef is C++ header file. Can you rename your source file from main.c to main.cpp

1 Like

Its already main.cpp.

Here’s the error when making:

[ 50%] Building CXX object CMakeFiles/Game.dir/main.cpp.o
In file included from /home/user/VSCode Projects/GameTest5/main.cpp:1:
/usr/include/GLFW/glfw3.h:103:10: fatal error: cstddef.h: No such file or directory
  103 | #include <cstddef.h>
      |          ^~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/Game.dir/build.make:76: CMakeFiles/Game.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Game.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Still shows same errors except when building:

[ 50%] Building CXX object CMakeFiles/Game.dir/main.cpp.o
/home/user/VSCode Projects/GameTest5/main.cpp: In function ‘int main()’:
/home/user/VSCode Projects/GameTest5/main.cpp:8:23: error: expected initializer before ‘glfwCreateWindow’
    8 |     GLFWwindow window glfwCreateWindow(600, 600, "this", NULL, NULL);
      |                       ^~~~~~~~~~~~~~~~
/home/user/VSCode Projects/GameTest5/main.cpp:9:28: error: ‘window’ was not declared in this scope
    9 |     glfwMakeContextCurrent(window);
      |                            ^~~~~~
/home/user/VSCode Projects/GameTest5/main.cpp:10:23: error: ‘GLADloadproc’ was not declared in this scope
   10 |     gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
      |                       ^~~~~~~~~~~~
/home/user/VSCode Projects/GameTest5/main.cpp:10:5: error: ‘gladLoadGLLoader’ was not declared in this scope
   10 |     gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
      |     ^~~~~~~~~~~~~~~~
/home/user/VSCode Projects/GameTest5/main.cpp:17:5: error: ‘unit32_t’ was not declared in this scope; did you mean ‘uint32_t’?
   17 |     unit32_t v;
      |     ^~~~~~~~
      |     uint32_t
/home/user/VSCode Projects/GameTest5/main.cpp:18:22: error: ‘v’ was not declared in this scope
   18 |     glGenBuffers(1, &v);
      |                      ^
/home/user/VSCode Projects/GameTest5/main.cpp:18:5: error: ‘glGenBuffers’ was not declared in this scope; did you mean ‘glReadBuffer’?
   18 |     glGenBuffers(1, &v);
      |     ^~~~~~~~~~~~
      |     glReadBuffer
/home/user/VSCode Projects/GameTest5/main.cpp:19:5: error: ‘glBindBuffer’ was not declared in this scope; did you mean ‘glReadBuffer’?
   19 |     glBindBuffer(GL_ARRAY_BUFFER, v);
      |     ^~~~~~~~~~~~
      |     glReadBuffer
/home/user/VSCode Projects/GameTest5/main.cpp:20:5: error: ‘glBufferData’ was not declared in this scope
   20 |     glBufferData(GL_ARRAY_BUFFER, sizeof(t)*sizeof(t)/sizeof(t[0]), &t[0], GL_STATIC_DRAW)
      |     ^~~~~~~~~~~~
/home/user/VSCode Projects/GameTest5/main.cpp:22:5: error: ‘glEnableVertexAttribArray’ was not declared in this scope
   22 |     glEnableVertexAttribArray(0);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/VSCode Projects/GameTest5/main.cpp:25:17: error: ‘GL_COLOR_ARRAY_BUFFER_BIT’ was not declared in this scope; did you mean ‘GL_COLOR_ARRAY_BUFFER_BINDING’?
   25 |         glClear(GL_COLOR_ARRAY_BUFFER_BIT);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                 GL_COLOR_ARRAY_BUFFER_BINDING
make[2]: *** [CMakeFiles/Game.dir/build.make:76: CMakeFiles/Game.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Game.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

The code is from youtube: 7I0eNh2XdvA?si=uxnH-d-DoortxBxs

It looks like this:

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

int main()
{
    glfwInit();
    GLFWwindow window glfwCreateWindow(600, 600, "this", NULL, NULL);
    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
    float t[] = {
        -0.5f, -0.5f, 0.0f,
        -0.0f, 0.5f, 0.0f,
        0.5f, -0.5f, 0.0f
    };

    unit32_t v;
    glGenBuffers(1, &v);
    glBindBuffer(GL_ARRAY_BUFFER, v);
    glBufferData(GL_ARRAY_BUFFER, sizeof(t)*sizeof(t)/sizeof(t[0]), &t[0], GL_STATIC_DRAW)
    glVertextAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, (void*)0);
    glEnableVertexAttribArray(0);
    while(!glfwWindowShouldClose(window))
    {
        glClear(GL_COLOR_ARRAY_BUFFER_BIT);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glfwSwapBuffers(window)
    }

}

Searching the FS doesn’t come up with any file called cstddef.h or cstddef.hpp
Not sure why gcc doesn’t include it.

guess, code is gcc-13 only.

Aw, dagnabit, I didnt notice this was in ARM (again).

In my defense its not on front listing;

Welp…

You can check yourself:

sudo pacman -Fyx 'cstddef.h'

Doesn’t find it:

extra/asio 1.28.0-1
    usr/include/asio/detail/cstddef.hpp
extra/boost 1.83.0-2 [installed]
    usr/include/boost/asio/detail/cstddef.hpp
extra/passenger 6.0.18-1
    usr/lib/passenger/src/cxx_supportlib/vendor-modified/boost/asio/detail/cstddef.hpp

should be in /usr/include/linux or smth, that’s where the stddef.h is.

Then it really should be in the linux-api-headers package. I downloaded the 6.1 and 6.7-rc tarballs and cstddef.h is not in either tree anywhere.

I must be wrong then, where would it be?

I’m trying to find out. I ran across that it is in the C++ Utility library what ever that is.

that might be it

no still can’t find it, must have different versions

I just checked and it is not in licutl

Added:

And it is not in any package in the arch-arm repo

@AltiusGames Looks like he needs a newer glfw.

https://github.com/glfw/glfw/blob/master/include/GLFW/glfw3.h#L103

glfw version in our repo

[ray@jellyfin ~]$ pacman -Si glfw-x11
Repository : extra
Name : glfw-x11
Version : 3.3.8-1
Description : A free, open source, portable framework for graphical
application development (x11)
Architecture : aarch64
URL : https://www.glfw.org/
Licenses : custom:ZLIB
Groups : None
Provides : glfw=3.3.8
Depends On : libxi libxrandr libxinerama libxcursor libgl
Optional Deps : None
Conflicts With : glfw
Replaces : glfw
Download Size : 103.99 KiB
Installed Size : 529.50 KiB
Packager : Arch Linux ARM Build System builder+seattle@archlinuxarm.org
Build Date : Sat 23 Jul 2022 10:06:21 AM CDT
Validated By : MD5 Sum SHA-256 Sum Signature

Running pacman -Si glfw-wayland gives this:

Repository      : extra
Name            : glfw-wayland
Version         : 3.3.8-1
Description     : A free, open source, portable framework for graphical
                  application development (wayland)
Architecture    : x86_64
URL             : https://www.glfw.org/
Licenses        : custom:ZLIB
Groups          : None
Provides        : glfw=3.3.8
Depends On      : wayland  libxkbcommon  libgl
Optional Deps   : None
Conflicts With  : glfw
Replaces        : None
Download Size   : 100.71 KiB
Installed Size  : 492.93 KiB
Packager        : Sven-Hendrik Haase <svenstaro@gmail.com>
Build Date      : Sat 23 Jul 2022 12:24:54 AM CDT
Validated By    : MD5 Sum  SHA-256 Sum  Signature

Which is the same version as your x11 installation.

I don’t know it you missed my point or not. The one’s in our repo (which we mirror from arch-arm) is a year and a half old and it is not the same as in the glfw github. They have #include <stddef.h> not #include <cstddef.h> in their gitlab. Also the glfw-git in AUR is flagged out of date. You need to rebuild gufw with the one in their git. Then hope that the code you borrowed from youtube is not old enough to use strings that was in cstddef.h which appears to now be depreciated.

just took a look at my code and fixing the sytax errors left me with a glad issue, so I’ll look into that.

Getting up-to-date repo’s worked.

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.