Missing stdout and GUI after running cross-compiled wxWidget app on Windows 10

Viewed 45

I downloaded the wxWidgets-3.1.3 source code and built it with the mingw-w64 on Ubuntu 18.04 by running these commands:

./configure --prefix=build/win64 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-cxx=11 --with-msw --enable-stl --enable-debug
make -j4
make install

My cpp code contains:

#include <unistd.h>
#include <iostream>
int main() {
  std::cout<<"Debug start main()"<<std::endl;
  fprintf(stderr,"...");
  sleep(3);
}

Then I build my application without including any wxWidget code (and only linking to the wxWidgets libs) for testing with CMake:

find_package(wxWidgets REQUIRED COMPONENTS gl core base aui)
add_executable(myapp main.cpp)
target_link_libraries(myapp ${wxWidgets_LIBRARIES})

I can build it by calling below command from the build folder:

cd build
cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/../cmake/mingw-w64.toolchain
      -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/bin
      -DCMAKE_BUILD_TYPE=Debug
..

The CMake toolchain file contains:

set(CMAKE_SYSTEM_NAME WindowsStore)
set(CMAKE_SYSTEM_VERSION 10.0)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc-posix)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++-posix)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong")
set(CMAKE_C_FLAGS_INIT "")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -pg -Wextra")
set(CMAKE_C_FLAGS_RELEASE "-O2 -Wall -Wextra")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -std=c++11")
set(CMAKE_CXX_FLAGS_INIT "")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall")

# where is the target environment located
set(CMAKE_FIND_ROOT_PATH
    /usr/${TOOLCHAIN_PREFIX} # mingw folder
    ${CMAKE_PREFIX_PATH} 
)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

I copy the exe file and run on Windows 10. However, I can't see the console output. The application does the sleep. Running the exe file with the gdb from the installed MinGW for Windows also doesn't print the printf output. If I remove the wxWidgets library from the target_link_libraries(), I can see the console output.

If the main.cpp contains the Hello World tutorial code from this site https://docs.wxwidgets.org/trunk/overview_helloworld.html, I can see the GUI.

What I observed, starting with wxIMPLEMENT_APP(MyApp); without int main() in the main.cpp can show the GUI correctly. However, starting the GUI with these code doesn't work:

#include <wx/wx.h>

int main(int argc, char *argv[]){
  wxEntryStart(wxArgc, argv);
  if (!wxTheApp || !wxTheApp->CallOnInit()){
    std::cout << "Failed!\n" << std::flush;
    return false;
  }
}

Any hint why?

0 Answers
Related