2

First of all, sorry if this is in the wrong category, as I am not sure what the cause of this problem is.

For educational purposes I have created a small "Hello World" application

#include <iostream>
int main() {
    std::cout << "Hello World\n";
    return 0;
}

I have tried compiling it with both Visual Studio as well as MINGW-64(g++ -m64 main.cpp), as a 64-bit application. It runs perfectly on my Windows computer, but when I try to run it within the latest Windows PE it doesn't print out any thing. I have also tried with std::cin so that the program doesn't stop right away, but the same thing happens - no output and no error. enter image description here

I know WinPE is very limited in terms of included libraries and subsystems, but I really thought that this simple Hello World app would run. The WinPE environment is 64-bit, that 's why I am compiling as 64-bit

Any ideas where I should start?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
ddybing
  • 77
  • 1
  • 8
  • maybe this helps you [LINK](https://stackoverflow.com/questions/17117728/how-to-run-c-executable-in-windows-pe). I dont know if this has changed in any way, but u may need a 32bit exe – skratchi.at Nov 10 '19 at 13:51
  • Thank you for the swift reply, but I think I should be able to run it as a 64-bit application. The target WinPE environment is 64-bit, which is why I am compiling it as a 64-bit application. – ddybing Nov 10 '19 at 14:04
  • COUT is a buffered stream. It looks like the buffer isn’t flushed before the program exits. You can flush the buffer and it should appear. – Freddy Nov 10 '19 at 14:39
  • Thanks for the reply, Freddy. Adding "<< std::flush" to the end of the line didn't help, if that's what you meant? – ddybing Nov 10 '19 at 14:43
  • Found the issue, see my comment to Lucas' answer. – ddybing Nov 10 '19 at 14:56

2 Answers2

4

I found the actual problem. I didn't compile the application statically which caused it to rely on dependencies not found in WinPE. I re-compiled it using the '-static' flag and it now works as expected on both WinPE and desktop versions of Windows.

ddybing
  • 77
  • 1
  • 8
1

Use

    std::cout << "Hello World" << std::endl;

std::endl will flush the content and add a \n at the end of your message.

ltabis
  • 113
  • 2
  • 7
  • Thanks for the reply. I found the actual problem. I didn't compile the application statically which caused it to rely on dependencies not found in WinPE. I re-compiled it using the '-static' flag and it now works as expected on both WinPE and desktop versions of Windows. – ddybing Nov 10 '19 at 14:54