Edro
Edro

Reputation: 125

cannot open source file "begin_code.h" (dependency of "SDL2/SDL.h")

When attempting to setup SDL2 with VS Code in Ubuntu 20.01 LTM I get the following VS Code error:

cannot open source file "begin_code.h" (dependency of "SDL2/SDL.h")

Any tips?

Upvotes: 3

Views: 7745

Answers (3)

Paulo Silva
Paulo Silva

Reputation: 179

in case you don't have the "c_cpp_properties.json" file in your folder.

Different answer than above, but I believe might be a better approach.

to create the c_cpp_properties.json on your workspace do the following:

  1. ctrl + shift + p (opens the command palette)
  2. search for "C/C++: Edit Configurations (JSON)" and click on it
  3. "c_cpp_properties.json" file will be created on your workspace
  4. add "/usr/include/SDL2/" to your "c_cpp_properties.json" like https://stackoverflow.com/a/64187964/8540466
  5. reload C/C++ IntelliSense extension.

I'm assuming you already have the extension "C/C++ IntelliSense, debugging, and code browsing" installed on your vscode.

After these steps this problem was fixed for me.

Upvotes: 1

Heliton Martins
Heliton Martins

Reputation: 1221

If you, like me, don't have the c_cpp_properties.json file in your project, you can solve it by adding the following line to your settings.json (in VSCode, hit Ctrl+Shift+P and search for Open settings (JSON)):

{
    // ...
    "C_Cpp.default.includePath": ["/usr/include/SDL2", "${default}"],
    //...
}

Upvotes: 0

Edro
Edro

Reputation: 125

Just add "/usr/include/SDL2/" to your c_cpp_properties.json like so:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/SDL2/"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu18",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

Upvotes: 4

Related Questions