Jump to content
  • Advertisement
MarcusAseth

Include SDL2 using Visual Studio Code, help :\

Recommended Posts

Hi guys, long time no see, reason is I have put aside programming and focused on my japanese study, I'm still not done with it yet but from time to time I might try to code something just to not lose what I learn until I'm ready to further this as well again :) 

So I was trying out Visual Studio Code (got tired of the starting time of Visual Studio 2017) and I'm trying to set up SDL2, but I'm getting the following error message when I build:

Quote

main.cpp:2:22: fatal error: SDL2/SDL.h: No such file or directory
 #include "SDL2/SDL.h"

That has to be a lie, because I've already added the include path thus fixing the squiggly lines under  #include "SDL2/SDL.h" , and I'm also getting intellisense for SDL functions.

I've been strugling with this for several hours, and I cannot find a solution, so is time to ask for help :P

Below my task.json and c_cpp_properties.json , any idea of why I am getting this error and how to get it to build?

task.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g","*.cpp", "-o", "Pacman", "-lSDL2", "-lSDL2main"
            ]
        }
    ],
    "group": {
        "kind": "build",
        "isDefault": true
    },
    "problemMatcher":"$gcc"
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ]
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Win32",
            "includePath": [
                "Z:/Dependencies/SDL2-2.0.5/lib/x86",
                "Z:/Dependencies/SDL2-2.0.5/SLD2",
                "Z:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/include/*",
                "Z:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/atlmfc/include/*",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt",
                "${workspaceRoot}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "Z:/Dependencies/SDL2-2.0.5/SLD2",
                    "Z:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/include/*",
                    "Z:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/atlmfc/include/*",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 3
}

 

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
Advertisement

To further prove my include path aren't messed up, you can see the auto-complete when I type the include in the image below, so I cannot understand why when I build it tells me "No such file or directory"

PA0uDyn.png

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Solved :D

The solution was to add this 2 lines to the args of tasks.json

"-I Z:/Dependencies/SDL2-2.0.5/SLD2",
"-L Z:/Dependencies/SDL2-2.0.5/lib/x86", 

I guess the misunderstanding was in my assumption that the paths on the c_cpp_properties.json where for the compiler, those paths are probably only for intellisense purpose :)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!