Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Running Program Without IDE  (Read 9956 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« on: September 02, 2010, 02:18:38 am »
Hello

I am trying to create a program that will run directly off of a .exe file like most every program out there. However, whenever I double-click the .exe file it says: "The program can't start because sfml-graphics.dll is missing your computer. Try reinstalling the program to fix the problem."
I checked in my .cpp file's directory and I have all of the required dlls in there.

Here is my code:
Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <fstream>


using std::string;
using std::ios;
using std::ofstream;
using std::ifstream;

/*void PrintFile(void* UserData)
{
    ifstream inFile; // Declare inFile
    ofstream outFile; // Declare outFile
    if (!inFile.is_open())  //Check to see if file is open
    {
        inFile.open("mapCoords.txt", ios::in); //If not, open file for output
        inFile.close(); //Close File
    }
    else { //If the file was opened...
        inFile.close(); //Close it
    }
}*/

int main()
{
    //sf::Thread PrintFile(&PrintFile);
    //PrintFile.Launch();

    //ifstream inFile; // Declare inFile
    //ofstream outFile; // Declare outFile

    sf::Image IconImage;
    if (!IconImage.LoadFromFile("icon.bmp"))
        return EXIT_FAILURE;
    sf::Sprite Icon(IconImage);

    sf::Image CursorImage;
    if (!CursorImage.LoadFromFile("cursor.cur"))
        return EXIT_FAILURE;
    sf::Sprite Cursor(CursorImage);
    Cursor.SetCenter(0, 0);
    Cursor.SetPosition(1000,500);

    sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");
    App.SetIcon(64,64,IconImage.GetPixelsPtr());
    App.ShowMouseCursor(false);
    bool windowed = true;
    sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();

    sf::Font TypeKnight;
    if (!TypeKnight.LoadFromFile("Knights Templar.ttf"))
    {
        return EXIT_FAILURE;
    }
    sf::String Comma(" , ");
    Comma.SetFont(TypeKnight);
    Comma.Move(240,10);

    bool X = false;
    bool Y = false;
    std::string XCoord;
    std::string YCoord;
    sf::String Coord;
    Coord.SetFont(TypeKnight);
    Coord.Move(175,10);

    sf::String TopLeft("Text Input: ________________");
    TopLeft.SetFont(TypeKnight);
    TopLeft.Move(10,10);
    TopLeft.SetColor(sf::Color::White);

    sf::String Main("Press F12 to toggle the help menu");
    Main.SetFont(TypeKnight);
    Main.Move(10.f, 600.f);
    Main.SetColor(sf::Color::White);

    bool help = false;
    sf::String Help("Type A to add a coordinate\n\nType R to remove a coordinate\n\nType F to find a coordinate\n\nUse + and - to zoom in and out on the map\n\nUse the arrow keys to navigate the map\n\nPress F1 to toggle FullScreen mode\n\nPress ESC to exit the program\n\nPress F12 to toggle the help menu");
    Help.SetFont(TypeKnight);
    Help.Move(10.f,180.f);

    sf::String CopyRight("CopyRight 2010 Tyler Petresky :: All program code is subject to CopyRight Laws");
    CopyRight.SetFont(TypeKnight);
    CopyRight.SetColor(sf::Color::White);
    CopyRight.Move(1300.f, 125.f);
    CopyRight.Scale(0.5f, 0.5f);
    CopyRight.Rotate(-90.f);

    // Creates the PE map :: 7000x3000
    sf::Shape MapPh;
    MapPh.AddPoint(0,0,sf::Color(0,100,0));
    MapPh.AddPoint(9000,0,sf::Color(0,100,0));
    //MapPh.AddPoint(3500,1500,sf::Color(0,125,0));
    MapPh.AddPoint(9000,3000,sf::Color(0,100,0));
    MapPh.AddPoint(0,3000,sf::Color(0,100,0));
    MapPh.EnableFill(true);
    MapPh.EnableOutline(false);
    MapPh.SetOutlineWidth(10);

    sf::Shape PhMid = sf::Shape::Line(3000, 0, 3000, 3000, 20, sf::Color::Black);
    sf::Shape DrMid = sf::Shape::Line(6000, 0, 6000, 3000, 20, sf::Color::Black);
    sf::Shape HorMid = sf::Shape::Line(0, 1500, 9000, 1500, 20, sf::Color::Black);

    sf::Vector2f Center(4500, 1500);
    sf::Vector2f HalfSize(2250, 750);
    sf::View View(Center, HalfSize);
    View.Zoom(0.35f);

    enum State { State0, State1, State2, State3 };
    State myState = State0;
    int counter = 0;

    // Main loop
    while (App.IsOpened())
    {
        // Event loop
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Press escape : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();

            // Press F1 : Switch video mode
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F1)) {
                if (windowed == true) {
                    App.Create(DesktopMode, "Laz's Interactive Map :: The Wrath... :: PvP Created", sf::Style::Fullscreen);
                    windowed = false;
                }
                else {
                    App.Create(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");
                    windowed = true;
                }
            }

            // Press F12 : Toggle help menu
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F12)) {
                if (help == false) {
                    help = true;
                }
                else {
                    help = false;
                }
            }

            // Press A : Add coords
            if (myState == State0 && (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
            {
                std::cout << "ONE" << std::endl;
                myState = State1;
            }
            if (myState == State1 && (Event.Type == sf::Event::TextEntered))
            {
                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Return))
                {
                    if (X == false)
                        X = true;
                    else
                        Y = true;
                }
                std::cout << "TWO" << std::endl;

                if (X == false && counter < 5) {
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "THREE" << std::endl;
                        XCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(XCoord);
                        std::cout << XCoord << std::endl;
                    }
                    ++counter;
                }

                if (X == true && Y == false && counter < 5) {
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "FOUR" << std::endl;
                        YCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(YCoord);
                        std::cout << YCoord << std::endl;
                    }
                    ++counter;
                }
            }
        }



        float ElapsedTime = App.GetFrameTime();

        // Move the map around the screen
        float Offset = 2000.f * App.GetFrameTime();
        if (App.GetInput().IsKeyDown(sf::Key::Up))    View.Move( 0,      -Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  View.Move( 0,      Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Left))  View.Move(-Offset,  0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) View.Move(Offset,  0);

        // Zoom and unzoom using + and - keys
        if (App.GetInput().IsKeyDown(sf::Key::Add))      View.Zoom(1.005f);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) View.Zoom(0.994f);

        App.SetView(View);

            App.Clear();

            App.Draw(MapPh);
            App.Draw(PhMid);
            App.Draw(DrMid);
            App.Draw(HorMid);

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

            App.Draw(TopLeft);

            if (help == true)
                App.Draw(Help);
            else
                App.Draw(Main);

                App.Draw(Coord);
                if (X == true)
                    App.Draw(Comma);

            App.Draw(CopyRight);

            sf::Vector2f CursorPos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
            Cursor.SetPosition(CursorPos);
            App.Draw(Cursor);

            App.Display();
    }



    return 0;
}


Any help would be greatly appreciated. ;)

Thanks

===================================
EDIT:
----------------------------------
I'm using Code::Blocks IDE
-Wander

Recruit0

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Running Program Without IDE
« Reply #1 on: September 02, 2010, 03:11:06 am »
The DLLs need to be in the same folder as the EXE. Or, you can put the DLLs in the system folder (I forget which since I use linux now).

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #2 on: September 02, 2010, 03:20:01 am »
Okay. I stuck all of the SFML dlls in with the .exe. It is no longer asking for SFML dlls... Now it's asking for one I'm unfamiliar with: libgcc_s_dw2-1.dll.

Is this in the MinGW? SFML folder?

If I want to send my program to a friend does he need to install SFML and MinGW??
-Wander

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Running Program Without IDE
« Reply #3 on: September 02, 2010, 06:02:03 am »

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #4 on: September 03, 2010, 11:44:29 pm »
Thanks!

It is no longer asking for dlls but when I double click on the .exe file, nothing happens....
-Wander

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Running Program Without IDE
« Reply #5 on: September 04, 2010, 02:14:24 am »
Is it a console application, what i want to know exactly from this is that when u execute programe from the IDE any console is shown ?

If u don't allow the console then it could be a fileloading path error of files " 'icon.bmp' , 'cursor.cur' .... "  which is not shown on the console ^^ .
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #6 on: September 04, 2010, 06:51:10 am »
I had it as a GUI Application, but then I changed it to Console Application and the console still won't show up. :/
-Wander

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Running Program Without IDE
« Reply #7 on: September 04, 2010, 04:48:52 pm »
Did u rebuild the project ?
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #8 on: September 04, 2010, 06:42:35 pm »
Yes I did, still doesn't work.
-Wander

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #9 on: September 04, 2010, 08:13:02 pm »
OKAY! I managed to get the console to pop up and it says it fails to load my image: Pheonix.bmp. It's in the folder with my .cpp file. So I'm thoroughly confused.
-Wander

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Running Program Without IDE
« Reply #10 on: September 04, 2010, 11:16:07 pm »
Is the image also in the folder of the exe?

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #11 on: September 05, 2010, 01:06:51 am »
Okay I got it to run. But there is a lot of files sitting around in their with the .exe is there a way I tell the program where to look for the files so I can organize the folder?
-Wander

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Running Program Without IDE
« Reply #12 on: September 05, 2010, 02:12:56 am »
Folders were created for such a goal :wink:

For example :

- Create an Image Folder and place it with the .exe nammed "Images" for images so u can load it as the following "PlayerImage.LoadFromFile("Images/Player.png") ".

- Create a folder to put fonts on...

Is this what u need ?
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Running Program Without IDE
« Reply #13 on: September 05, 2010, 02:16:45 am »
Exactly! Thanks!

My folder is prearranged as:
Project Folder > bin > Debug > .exe
Project Folder > obj > Debug > main.o

Source code being in the Project Folder.

Is there a way to get everything in the Project Folder including the .exe and the main.o file?
-Wander

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Running Program Without IDE
« Reply #14 on: September 05, 2010, 02:23:34 am »
You have to do this manually.

But you have to know that u don't need the 'main.o' to run the application  :wink:.

All you need is the ressource files (images, fonts, cursor ...) in addition to the librarys (.Dll files ) if you are using dynamic libraries of sfml.
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.