找到你要的答案

Q:Cannot run release build on a PC without visual studio

Q:无法在没有VisualStudio的PC上运行版本发布

The title pretty much says it all.

I am learning C++ at the moment and decided to try to make a game. My friend who also wants to learn C++, but does not have VS installed tried to run it, and it crashed on start up.

It was fine when I ran it from outside VS, and I sent it to him in a ZIP file with all the DLLs and in a release build. Unsure why this is happening, anyone have any ideas?

Here is the code, its fairly badly written and the readability is poor (Sorry.)

#include "stdafx.h"
#include <SFML/Graphics.hpp>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>

int main()
{
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);

    bool gameover(1);

    sf::RenderWindow window(sf::VideoMode(240, 500), "Hangman but not very good.");
    sf::Text text;
    sf::Font font;
    sf::Sprite sprite;
    sf::Texture texture;

    texture.loadFromFile("0.png");

    sprite.setTexture(texture);

    char uInput[11] = {0};
    char displayed[11] = {0};
    bool setup = false;
    int charCount(0);
    int iii(0);
    bool correct(0);
    long long wrongGuesses(0);
    int wordlength(0);
    long long gameoverCounter(0);
    char currentGuess = 0;
    bool bypass = true;
    char pngC = '1';
    char IOarray[] = "x.png";
    bool firstSetup = true;
    int correctCounter = 0;

    font.loadFromFile("Xefus.ttf");
    text.setColor(sf::Color::Yellow);
    text.setCharacterSize(24);
    text.setFont(font);
    text.setString("Please enter the word to guess, press enter to stop");

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

                if(event.type == sf::Event::TextEntered)
                {
                    bypass = true;

                    if(iii < 10 && !setup)
                        if(event.text.unicode < 128 && event.text.unicode > 96)
                        {
                            uInput[iii] = static_cast<char>(event.text.unicode);
                            ++iii;
                            ++wordlength;
                        }

                    {
                        for(int i = 0; i < wordlength; ++i)
                            if(event.text.unicode == uInput[i] && !firstSetup)
                            {
                                displayed[i] = uInput[i];
                                bypass = false;
                                ++correctCounter;
                            }
                            else if(bypass = true)
                                ++wrongGuesses;
                    }
                }

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
                    setup = true;

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace))
                {
                    uInput[iii] = 0;
                    iii -= 1;
                }
            }

            if(!setup)
            {
                text.setString(uInput);
                displayed[wordlength - 1] = ('*');
                setup = false;
            }
            else
            {
                text.setString(displayed);
                bypass = false;

                if(firstSetup)
                {
                    firstSetup = false;
                    gameoverCounter = 0;
                    wrongGuesses = 0;
                    correctCounter = 0;
                }

                if(wrongGuesses >= wordlength)
                {
                    ++gameoverCounter;
                    wrongGuesses = 0;
                    IOarray[0] = static_cast<char>(gameoverCounter + 48);

                    texture.loadFromFile(IOarray);
                }

                if(gameoverCounter >= 9)
                {
                    return 0;
                    window.clear();
                    window.draw(sprite);
                    window.draw(text);
                    window.display();
                }

                if(correctCounter >= wordlength)
                {
                    return 0;
                    window.clear();
                    window.draw(sprite);
                    window.draw(text);
                    window.display();
                }

                wrongGuesses = 0;
            }

            window.clear();
            window.draw(sprite);
            window.draw(text);
            window.display();
        }
    }
}

标题几乎说这一切。

我现在学习C++,决定尝试做一个游戏。我的朋友又想学C++,但没有与安装试运行,并在启动。

这是好的时候我跑了,从外面的VS,我送给他一个zip文件的所有DLL和发布版本。不确定为什么会发生这种情况,任何人有任何想法?

这里是代码,它写得相当糟糕,可读性很差(抱歉)。

#include "stdafx.h"
#include <SFML/Graphics.hpp>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>

int main()
{
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);

    bool gameover(1);

    sf::RenderWindow window(sf::VideoMode(240, 500), "Hangman but not very good.");
    sf::Text text;
    sf::Font font;
    sf::Sprite sprite;
    sf::Texture texture;

    texture.loadFromFile("0.png");

    sprite.setTexture(texture);

    char uInput[11] = {0};
    char displayed[11] = {0};
    bool setup = false;
    int charCount(0);
    int iii(0);
    bool correct(0);
    long long wrongGuesses(0);
    int wordlength(0);
    long long gameoverCounter(0);
    char currentGuess = 0;
    bool bypass = true;
    char pngC = '1';
    char IOarray[] = "x.png";
    bool firstSetup = true;
    int correctCounter = 0;

    font.loadFromFile("Xefus.ttf");
    text.setColor(sf::Color::Yellow);
    text.setCharacterSize(24);
    text.setFont(font);
    text.setString("Please enter the word to guess, press enter to stop");

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

                if(event.type == sf::Event::TextEntered)
                {
                    bypass = true;

                    if(iii < 10 && !setup)
                        if(event.text.unicode < 128 && event.text.unicode > 96)
                        {
                            uInput[iii] = static_cast<char>(event.text.unicode);
                            ++iii;
                            ++wordlength;
                        }

                    {
                        for(int i = 0; i < wordlength; ++i)
                            if(event.text.unicode == uInput[i] && !firstSetup)
                            {
                                displayed[i] = uInput[i];
                                bypass = false;
                                ++correctCounter;
                            }
                            else if(bypass = true)
                                ++wrongGuesses;
                    }
                }

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
                    setup = true;

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace))
                {
                    uInput[iii] = 0;
                    iii -= 1;
                }
            }

            if(!setup)
            {
                text.setString(uInput);
                displayed[wordlength - 1] = ('*');
                setup = false;
            }
            else
            {
                text.setString(displayed);
                bypass = false;

                if(firstSetup)
                {
                    firstSetup = false;
                    gameoverCounter = 0;
                    wrongGuesses = 0;
                    correctCounter = 0;
                }

                if(wrongGuesses >= wordlength)
                {
                    ++gameoverCounter;
                    wrongGuesses = 0;
                    IOarray[0] = static_cast<char>(gameoverCounter + 48);

                    texture.loadFromFile(IOarray);
                }

                if(gameoverCounter >= 9)
                {
                    return 0;
                    window.clear();
                    window.draw(sprite);
                    window.draw(text);
                    window.display();
                }

                if(correctCounter >= wordlength)
                {
                    return 0;
                    window.clear();
                    window.draw(sprite);
                    window.draw(text);
                    window.display();
                }

                wrongGuesses = 0;
            }

            window.clear();
            window.draw(sprite);
            window.draw(text);
            window.display();
        }
    }
}
answer1: 回答1:

Vikash is right, this is a case of missing runtime libraries. What you need is to install the right Redistributable package in your target computer.

Google and download the appropriate version for your application:

"Visual C++ Redistributable for Visual Studio YYYY" where YYYY is the year of your Visual Studio.

Once downloaded, install this on your target computer then run your application.

Andrew

Vikash是对的,这是一个缺少运行库的情况下。你需要的是在你的目标计算机上安装正确的可再发行包。

谷歌并下载相应版本的应用程序:

“Visual C++重新发布的Visual Studio yyyy”您的Visual Studio yyyy代表年。

一旦下载,安装在您的目标计算机,然后运行您的应用程序。

安得烈

answer2: 回答2:

One of the reasons for this type of problem is missing dlls. So make sure you have all dependent dlls available on the system.

One common mistake that we do while copying the dependent libraries is that we forget to copy c++ run time dlls which is required to run any C++ application. This library is installed with the visual studio, that is why the application is running on your system but not on your friend's.

C++ run time libraries are: msvcr, msvcrt, msvcp

Also you can use Dependency Walker software to check for any other missing dependencies.

Hope it helps

这一类问题的原因是缺少。所以你必须确保所有相关的DLL在系统。

一个常见的错误,我们在复制的依赖库是我们忘记复制C++运行时DLL是需要运行任何C++应用程序。这个库安装了Visual Studio,这就是为什么应用程序运行在您的系统上,而不是在您的朋友的

C++运行时库:msvcr、msvcrt,msvcp

您还可以使用依赖沃克软件检查任何其他缺少的依赖关系。

希望有帮助

c++  visual-studio-2012  sfml