首页 > 解决方案 > Visual Studio Code - SFML libraries not found

问题描述

I'm trying to experiment with SFML in VScode, but the libraries aren't being found for me.

I've tried changing the c_cpp_properties.json file to add the libraries to the includePath, but they're still not being found.

This is the main class:

#include <iostream>
#include <Window.hpp>
#include <Graphics.hpp>



int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        // window.draw(...);

        // end the current frame
        window.display();
    }

    return 0;
}

Here's the properties file:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/Users/arnavchandra/Desktop/tic/SFML-2.5.1-macos-clang/include/SFML/"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

For #include <iostream>, I'm getting this error:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/arnavchandra/Desktop/tic/main.cpp).

For #include <Graphics.hpp>, I'm getting this error:

cannot open source file "SFML/Window.hpp" (dependency of "Graphics.hpp")

When I run it, I get this error:

main.cpp:2:10: fatal error: 'Window.hpp' file not found 1 error generated.

标签: c++visual-studio-codesfml

解决方案


您应该尝试 putSFML-2.5.1-macos-clang/include/**而不是SFML-2.5.1-macos-clang/include/SFML/in includePath


推荐阅读