0

This is main.h, I shared with you just in case there would be something wrong here. But I don't think so.

Then, there is main.cpp which is the entry point of my program.
If I generate it with Visual Studio 2017, it will compile and run without errors but it will not print anything on the console.

I can't figure out why.

main.h:

#pragma once

#include <thread>

#include "GabEngine/MainEngine.h"
#include "GraphicInterface/Console.h"
#include "GabEngine/Globals.h"

int m_ScreenWidth = 500, m_ScreenHeight = 500;
GabEngine::Wind m_RootWindow;
GabEngine::MainEngine m_MainEngine(&m_RootWindow);
Globals::NetworkStatus NetStatus;
Networking::MainNetwork m_MainNetwork(&NetStatus);

void TaskConsole();
void TaskNetwork();

main.cpp:

#include "GraphicInterface/main.h"
#include <iostream>

#undef main

void TaskConsole()
{
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        GabEngine::FatalError("Failed to initialize SDL");
    }

    m_RootWindow.Create("Utryon", m_ScreenWidth, m_ScreenHeight, 2);
    m_MainEngine.InitShaders();
    m_MainEngine.InitCEGUI("C:/Users/Bob/Documents/Visual Studio 2017/Projects/Utryon/GabEngine/GUI");
    m_MainEngine.LoadScheme("UtryonLook.scheme");
    m_MainEngine.SetFont("DejaVuSans-10");

    GraphicInterface::Console MainConsole(&m_MainEngine, &m_MainNetwork);
    MainConsole.InitConsole();
    MainConsole.Run();
}

void TaskNetwork()
{
    m_MainNetwork.Run();
}

int main(int argc, char** argv)
{
    std::cout << "Here 1" << std::endl;  //It is supposed to print Here 1
    thread ConsoleThread(TaskConsole);
    thread NetworkThread(TaskNetwork);

    ConsoleThread.join();
    NetworkThread.join();

    // End of program
    return 0;
}
TigerTV.ru
  • 1,058
  • 2
  • 16
  • 34
  • 4
    why do you use #undef main? – TigerTV.ru Feb 01 '18 at 03:23
  • one doubt: What is use of Command Line Argument i.e. argv ? I don't find it in code. – Ravi Shinde Feb 01 '18 at 03:27
  • Implementations of functions 'ConsoleThread' and 'NetworkThread' must be in main.cpp file. – TigerTV.ru Feb 01 '18 at 03:34
  • One reason you might not be seeing any output is because the std::cout stream isn't being flushed. Try using std::cerr, which can be losely described as an 'auto-flushed std::cout'. http://www.cplusplus.com/reference/iostream/cerr/ – avlec Feb 01 '18 at 03:35
  • And as @TigerTV.ru mentioned with function implementations, implementations of most multi-line functions should be kept in the .cpp files and leave prototyping to the .h files. – avlec Feb 01 '18 at 03:57
  • I use #undef main because there is a macro definition named main in SDL that generate a conflict otherwise. I did the implementation of functions in .cpp files, thanks. But it didn't solved the issue, std::cerr n either. What could it be? I mean how can something happen before the first line of main? It does not reach the first line... – Gabriel Proulx Feb 01 '18 at 04:36
  • 4
    The constructors of your global and static objects will execute before main() does. Try putting printf/cout commands into the constructors of those objects; perhaps the execution is getting stuck in an infinite loop inside one of them, or something like that. – Jeremy Friesner Feb 01 '18 at 04:43
  • It is probably bombing out in one of your global variables or constructors of global variables. Before the first line of main() runs, the C and C++ runtime initialize global variables. Try setting breakpoints on your global variables and constructors of classes that have global instances. In my debugger (Visual C++), I can set to break whenever an exception is thrown. That is very handy. – Joseph Willcoxson Feb 01 '18 at 04:43
  • Did you forget to include `#include `, which contains `cout`, in your `main.cpp`? – pgngp Feb 01 '18 at 04:57
  • @GabrielProulx *I mean how can something happen before the first line of main?* -- This is a fundamental of C++. Global instances of classes have their constructors run before executing `main()`. – PaulMcKenzie Feb 01 '18 at 05:01
  • please have a better read mr n.m. This is not about sdl main – Gabriel Proulx Feb 01 '18 at 05:11
  • All evidence suggests that it is. If you have a conflict with SDL main, ask a question about the conflict (see [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)). You probably won't see any console output in any case, because Windows subsystem programs don't use console by default. – n. m. could be an AI Feb 01 '18 at 06:38
  • If you insist on undrfining main anyway, you should probably try to use your debugger. – n. m. could be an AI Feb 01 '18 at 06:46
  • Do you compile your program as "Windows Application" (as opposed to "Console Application")? Windows applications don't show console by default. – el.pescado - нет войне Feb 01 '18 at 07:57
  • Do not accept my last edition of the question. – TigerTV.ru Feb 01 '18 at 13:17

0 Answers0