question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C++ SDL.h file not found

See original GitHub issue

Greetings,

I am using the Clangd extension on VS Code. VS Code reports the following error on my #include <SDL2/SDL.h>.

'SDL2/SDL.h' file not found clang(pp_file_not_found)

Running make results in no errors. Here is my Makefile:

CXXFLAGS = -Wall -Werror -std=c++11
SDL2FLAGS = -lSDL2
execs = chip8emu

all: chip8emu

chip8emu: chip8.cc chip8emu.cc
	$(CXX) $(CXXFLAGS) $(SDL2FLAGS) -o $@ $^

clean:
	rm -f $(execs)

I used bear, as per instructions on the clangd getting started page.

make clean; bear -- make

This results in the following compile_commands.json.

[
  {
    "arguments": [
      "/usr/bin/c++",
      "-c",
      "-Wall",
      "-Werror",
      "-std=c++11",
      "-o",
      "chip8emu",
      "chip8.cc"
    ],
    "directory": "/Users/jasjeet/chip8",
    "file": "/Users/jasjeet/chip8/chip8.cc",
    "output": "/Users/jasjeet/chip8/chip8emu"
  },
  {
    "arguments": [
      "/usr/bin/c++",
      "-c",
      "-Wall",
      "-Werror",
      "-std=c++11",
      "-o",
      "chip8emu",
      "chip8emu.cc"
    ],
    "directory": "/Users/jasjeet/chip8",
    "file": "/Users/jasjeet/chip8/chip8emu.cc",
    "output": "/Users/jasjeet/chip8/chip8emu"
  }
]

However, after restarting VS Code the error is still present. I have also tried adding “-I SDL2” to “arguments”.

System information Clangd extension version v0.1.11 Operating system: MacOS 11.5.2 SDL2 and bear were installed using Homebrew.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasrangicommented, Sep 13, 2021

echo | clang++ -E -v - | grep "/usr/local/include" verified that the output includes that path:

#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/12.0.5/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.

Adding -I /usr/local/include/ to CXXFLAGS in the Makefile, re-generating compile_commands.json by running make clean; bear -- make, and reloading the file in VS Code has cleared the errors. Thank you!

1reaction
HighCommander4commented, Sep 13, 2021

I’m guessing the compiler has /usr/local/include in its default search path (but for some reason clangd does not?)

You can verify this by running echo | clang++ -E -v -: does the output include /usr/local/include?

(As a workaround, adding -I /usr/local/include/ to your CXXFLAGS and re-generating the compile_commands.json should fix the issue.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

g++ compiler error: 'SDL.h' file not found · Issue #5167 - GitHub
From the build error, the command arguments for the g++ compiler needs to know the include path of "SDL.h". Can you try using...
Read more >
SDL2 headers not being found when compiling os x
Does find /Library/Frameworks/SDL2.framework -name "SDL.h" find that header file? Is it under an SDL2 directory or somewhere else? – Drew MacInnis.
Read more >
Setting up SDL 2 on Visual Studio 2019 Community
Cannot open include file: 'SDL.h': No such file or directory ... This means Visual C++ cannot find the SDL header files and you...
Read more >
Cant find SDL.h - Windows, MingW, Cmake and SLD2 (in ...
I want to add SDL2 to a Cmake Project, using C++ in VSCode on Windows, but using Mingw64 from Msys2 (g++). This is...
Read more >
SDL.h is not found? : r/cpp_questions - Reddit
Hi, I'm trying to make a game engine. I've created a little test that's building as a static library and another project that's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found