2015-05-02 99 views
1

標題幾乎說明了一切。不能在沒有Visual Studio的PC上運行版本構建

我正在學習C++,並決定嘗試製作遊戲。我的朋友也想學習C++,但沒有安裝VS,試圖運行它,它在啓動時崩潰。

當我從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(); 
     } 
    } 
} 
+1

在不同的PC上運行該程序時出現的確切錯誤消息是什麼? –

+0

您是否試圖將所有依賴關係包含在[靜態鏈接]中(http://stackoverflow.com/questions/37398/how-do-i-make-a-fully-statically-linked-exe-with-visual-studio -express-2005)exe? – mins

+0

感謝您的回覆,我應該靜態鏈接SFML還是隻是在您發佈的帖子中提到的那個? @分鐘? –

回答

0

Vikash是正確的,這是缺少運行庫的情況。您需要的是在目標計算機中安裝正確的Redistributable軟件包。

谷歌和下載應用程序的相應版本:

的Visual C++可再發行的Visual StudioYYYY」 裏YYYY是你的Visual Studio的一年。

下載後,將其安裝到目標計算機上,然後運行您的應用程序。

Andrew

+0

Is there任何方法都可以,或者它是所有應用程序的標準嗎? –

+0

這是最簡單的方法,更困難的方法是使用Dependency Walker,確定應用程序需要什麼DLL然後創建一個安裝程序/軟件包。與您的應用程序一起在同一個文件夾中。 –

+0

好的,非常感謝您的回覆c: –

0

其中的一個原因這種類型的問題是缺少DLL文件。因此,請確保您的系統上有所有可用的dll。

我們在複製依賴庫時所犯的一個常見錯誤是,我們忘記複製運行任何C++應用程序所需的C++運行時dll。這個庫與Visual Studio一起安裝,這就是爲什麼應用程序在您的系統上運行,而不是在您的朋友的。

C++運行時庫:msvcr,MSVCRT,msvcp

您也可以使用Dependency Walker中的軟件來檢查任何其他缺少的依賴關係。

希望它可以幫助

相關問題