简体   繁体   中英

internal compiler error Visual Studio Community 2017 with SFML API

When trying to compile a c++ code, including the sfml api libraries, the following error occurs:

Internal Compiler Error in 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.10.25017\\bin\\HostX86\\x86\\CL.exe' Choose the Technical Support command on the Visual C ++ Help menu, Or open the help desk file for more information C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\VC\\VCTargets\\Microsoft.CppCommon.targets(358,5): error MSB6006: "CL.exe" Was terminated with code 2.

I searched on the internet for a solution for this, but I couldn't solve it... When I asked on the visual studio forum for some help, the only answer I got was this:

“Thank you for your feedback! This issue has been fixed and it will be available in the next update to Visual Studio 2017. Thank you for helping us build a better Visual Studio!”

Heres the code with the error:

#include <SFML\Graphics.hpp>

int main() {

sf::RenderWindow window(sf::VideoMode(640, 480), "Bouncing Mushroom");

sf::Texture mushroomTexture;
mushroomTexture.loadFromFile("mushroom.png");
sf::Sprite mushroom(mushroomTexture);
sf::Vector2u size = mushroomTexture.getSize;
mushroom.setOrigin(size.x / 2, size.y / 2);
sf::Vector2f increment(0.4f, 0.4f);

while (window.isOpen())
{
sf::Event evnt;
while (window.pollEvent(evnt))
{
if (evnt.type == sf::Event::Closed)
window.close();
}

if ((mushroom.getPosition().x + (size.x / 2) > window.getSize().x && increment.x > 0) || (mushroom.getPosition().x - (size.x / 2) < 0 && increment.x < 0))
{
// Reverse the direction on X axis.
increment.x = -increment.x;
}

if ((mushroom.getPosition().y + (size.y / 2) > window.getSize().y && increment.y > 0) || (mushroom.getPosition().y - (size.y / 2) < 0 && increment.y < 0))
{
// Reverse the direction on Y axis.
increment.y = -increment.y;
}

mushroom.setPosition(mushroom.getPosition() + increment);
window.clear(sf::Color(16, 16, 16, 255)); // Dark gray.
window.draw(mushroom); // Drawing our sprite.
window.display();

}

Internal compiler errors usually mean something is wrong with the compiler and seeing that it is VS 2017, I would not be surprised if it is a bug since it is a newer version of VS. In the meantime, you can try to find the line of code that triggers this bug and find an alternative solution or use an older version of Visual Studio.

I downloaded visual studio 2015 and tried to run the code in it(all the tutorials of sfml are made in vs 2015) and the code run.

I believe the problem is that the libraries of sfml are not compatible with vs 2017 yet, so the solution is simple:

-use Visual Studio 2015 or

-recompile the libraries for Visual Studio 2017(I dont know how to do that)

Well if this is literally the code you are trying to compile there are 2 syntax errors:

1.- In line 10

mushroomTexture.getSize;

getSize is a method from sf::Texture class not a member so just add ();

mushroomTexture.getSize();

2.- There is a missing '}' at the end of the main function. (I think you just didn't copied this one correctly but check it out anyways.

    window.display();

    }
} <---- end of main() missing

If this didn't solve your problem, then you might have the wrong SFML files for your VS version, if you are using VS 2017 download the Visual C++ 14 (2015) - 32-bit version https://www.sfml-dev.org/download/sfml/2.4.2/ it works for VS 2015 & 2017 (i used it on VS 2017 to test your example and it ran without problems).

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