简体   繁体   中英

Problems with the c++ library SFML (#include)

I'm having trouble with the c++ library SFML I'm trying to make a simple and portable game for fun and as a challenge. I've decided to use SFML as it looks easy.

The problem is that every time I try to link the library I get a linking error. No mater where the files are located it always dosen't work. So I thought it was some Visual Studio error. So my instinct decited to switch to a dev c++ project. That didn't work either. I followed many tutorials looked at many forms for nothing to work. By the way i did the EXACTLY same thing in Visual Studio as in Dev C++ so i will not be showing screenshots of VS 2022

#include<iostream>
#include<Windows.h>
#include "SFML/Graphics.hpp"




/*int WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
    
}*/

//For Debbuining. The one above is for release
int main(){
    sf::RenderWindow window(sf::VideoMode(200,200), "SFML Works!");

    sf::CircleShape shape(100.f);

    shape.setFillColor(sf::Color::Green);

    

    while(window.isOpen()){

        sf::Event event;

            while(window.pollEvent(event)){

                if(event.type == sf::Event::Closed)

                window.close();

            }

    

    window.clear();

    window.draw(shape);

    window.display();

    

    }

}

SCREENSHOTS

screenshot1

screenshot2

screenshot3

screenshot4

screenshot5

screenshot6

I was expecting a window to pop up and show a green circle.

I recommend vcpkg .

First, install vcpkg and then sfml(vcpkg install sfml).

You can use sfml in visual studio.

By the way, you need to comment out #include <Windows.h> .

After set up you can use #include <SFML/Graphics.hpp> , too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM