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

Author Topic: Program immediate closes  (Read 3034 times)

0 Members and 1 Guest are viewing this topic.

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Program immediate closes
« on: March 04, 2017, 02:04:13 pm »
I have some fairly basic code that was copied from the tutorials and I can't seem to get anything to work properly, It's just exiting with exit code 0.
I'm using Windows 10, Clion, and 32bit MinGW that was provided on the download page with the 32bit SFML counterpart.
Image for reference: http://i.imgur.com/704iEjm.png
I've tried with multiple modules however this is the code I'm currently attempting to use:
#include "conio.h"
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::Clock clock; // starts the clock
    sf::Time elapsed1 = clock.getElapsedTime();
    std::cout << elapsed1.asSeconds() << std::endl;
    clock.restart();
    sf::Time elapsed2 = clock.getElapsedTime();
    std::cout << elapsed2.asSeconds() << std::endl;
    getch();
    return 0;
}
 

The only ways I have managed to make this run is by removing the SFML code or by making it unreachable.

As of writing this it's 2am and I have been attempting this for 8-10 hours, so I'll be sleeping for the next few hours.
If my explanation of what happens is inadequate (as they often are) I can make a short video in the morning.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Program immediate closes
« Reply #1 on: March 04, 2017, 02:19:46 pm »
Quote
It's just exiting with exit code 0.
And that's what it's supposed to do, so what exactly do you expect? Do you mean that nothing is printed to the console before it exits?
Laurent Gomila - SFML developer

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Program immediate closes
« Reply #2 on: March 04, 2017, 02:24:38 pm »
So long as the sfml code is reachable it just closes, even if I put something such as getch() in front of all of it. I have also attempted the generic window code and that has exactly the same result.
Edit: Even break points do nothing

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: Program immediate closes
« Reply #3 on: March 04, 2017, 02:32:54 pm »
just a guess

but somewhere I think you're supposed to set the compiler subsystem to
console

it may show that somewhere in the tutorials

when I create an sfml program in codeblocks, I set the subsystem to console even though I'm creating a windowed application

the window displays just the way you expect (like a normal window with min / max buttons and so on)
but codeblocks also opens a command line window where it puts the output of cout 

you probably have the the subsystem set to
window

but you aren't calling a "create window" function
so the program just exits

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Program immediate closes
« Reply #4 on: March 04, 2017, 11:02:10 pm »
Unless I'm misunderstanding I don't think it's that, if I just try to run it it does so internally and produces an error, However if I run in debug mode it does produce a console.

Video for clarity: https://www.dropbox.com/s/usqh3l7bz4m8gwp/2017-03-05_10-59-15.mp4?dl=0
Video shows exactly what happens when I launch it as well as launching with an endless while loop at the end and front of the code
« Last Edit: March 04, 2017, 11:06:00 pm by corprall »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11036
    • View Profile
    • development blog
    • Email
Re: Program immediate closes
« Reply #5 on: March 04, 2017, 11:50:06 pm »
What if you don't run it through the debugger? What if you don't start it through CLion?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Program immediate closes
« Reply #6 on: March 05, 2017, 12:36:05 am »
That helped me figure out what was wrong, I needed libgcc_s_dw2-1.dll, libstdc++-6.dll, and libwinpthread-1.dll
It works when I move those files into the launch directory but what is the proper solution for this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11036
    • View Profile
    • development blog
    • Email
Re: Program immediate closes
« Reply #7 on: March 05, 2017, 12:50:24 am »
You'll need to copy them next to the binary or to the working directory when you want to run the application on its own.

For running it in the debugger/from the IDE, it should work fine, as CLion should add the compiler path to PATH or similar.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Program immediate closes
« Reply #8 on: March 05, 2017, 01:19:17 am »
It probably should do that but it's clear that it hasn't done that because after moving the files to the working directory I can run it from clion just fine.

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Program immediate closes
« Reply #9 on: March 05, 2017, 01:26:06 am »
clion does almost everything through cmake, do I need to change anything in there? I'm still fairly new to cmake.

corprall

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Program immediate closes
« Reply #10 on: March 05, 2017, 03:44:52 am »
I was wrong, it's the sfml libraries that were failing.
I copied and pasted a cmake file from some tutorial and it worked, there must have been some small mistake that I missed.
Edit: Never mind, still not working.
cmake_minimum_required(VERSION 3.2)
project(SFMLDemo)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(SFMLDemo ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SFMLDemo ${SFML_LIBRARIES})
endif()
« Last Edit: March 05, 2017, 04:40:28 am by corprall »

 

anything