Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"No such file or directory" Why does my c build file can't build my exe if my files are in the right place?

Why is my build code won’t working informing that my file is not acessible if it is in the right folder and my c debugger work as well, finding no errors?

This is my build file:

set files=src\glad.c src\main.c set
libs=C:\Users\Ozzy\Documents\projects\c\lib\SDL2main.lib
C:\Users\Ozzy\Documents\projects\c\lib\SDL2.lib
C:\Users\Ozzy\Documents\projects\c\lib\freetype.lib

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

CL /Zi /I C:\Users\Ozzy\Documents\projects\c\include %files% /link
%libs% /OUT:mygame.exe

    OpenGL loader generated by glad 0.1.35 on Fri Jun 10 23:39:07 2022.

    Language/Generator: C/C++
    Specification: gl
    APIs: gl=3.3
    Profile: core
    Extensions:
        
    Loader: True
    Local files: False
    Omit khrplatform: False
    Reproducible: False

    Commandline:
        --profile="core" --api="gl=3.3" --generator="c" --spec="gl" --extensions=""
    Online:
        https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D3.3
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glad.h>

Print of the error and folder tree

>Solution :

From your screenshot I can see that the glad directory is next to main.c.

When including files, you can use either quotes ("") or angle brackets (<>), and they behave differently. The exact behavior depends on the compiler you are using and the settings for that compiler, but with cl.exe the default behavior is:

  • <>: Search within your include paths (which can be set using the /I flag).
  • "" Search relative to the location of the including file. If that doesn’t work, fall back to the include paths.

So if you replace:

#include <glad/glad.h>

With:

#include "glad/glad.h"

Then it should work.

Here’s some more information about how the #include directive works in cl.exe/MSVC.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading