1

I'm making a FLTK GUI in QtCreator. Please don't get angry at me for not using Qt to make my GUI, it's irrelevant.

Anyway, my project type is "Plain C++ Project", and this is my code (You probably don't need to read it, but I put it there just in case):

// include headers
#include <Windows.h>
#include <Fl/Fl.H>
#include <FL/FL_Window.h>
#include <FL/Fl_Button.h>
#include <FL/FL_ask.h>
// macro functions
#define UP(x) UNREFERENCED_PARAMETER(x)
// callback function
void callback(Fl_Widget *sender)
{
    sender->label("Thanks!");
}
// main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, 
    int nShowCmd)
{
    // UP's
    UP(hInstance);
    UP(hPrevInstance);
    UP(lpCmdLine);
    UP(nShowCmd);
    // window
    Fl_Window *window = new Fl_Window(250, 250, "Derp Window");
    window->begin();
    // button
    Fl_Button *button = new Fl_Button(10, 100, 230, 25, "Click Me!");
    button->callback(callback);
    // run
    window->end();
    window->show();
    int result = Fl::run();
    // delete ptr's
    delete button;
    delete window;
    // return
    return result;
}

When I run this, I get this warning, and two errors (Sorry about the small image, just zoom in your browser if you can't read it):

enter image description here

I know what a LNK2019 error is, in fact they are probably the bane of my existence. But in this case I have no idea why I am getting this. I think that you should also look at this, it's the text for my Qt projects .pro file:

TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt

win32: LIBS += -luser32 -lshell32 -lgdi32 -lole32 -ladvapi32

SOURCES += main.cpp

unix|win32: LIBS += -L$$PWD/../../../Desktop/C++/FLTK/lib/ -lfltk

INCLUDEPATH += $$PWD/../../../Desktop/C++/FLTK/include DEPENDPATH += $$PWD/../../../Desktop/C++/FLTK/include

This is probably the most important part: I never get any errors, and the program runs fine when I use int main() as my main function.

So, my question is why am I getting this, how do I fix it?

Name
  • 2,037
  • 3
  • 19
  • 28
  • 1
    I don't have a solution, but I think I see the crux of the problem. You're building a "console" app - not qt's "console", Windows' "console", so the entry point is main(), not WinMain(). Somehow, you need to tell it to build a "WINDOWS" app (linker option: SUBSYSTEM:WINDOWS). I see you have Visual Studio, look in Linker -> System -> Subsystem; I've also gone into "Advanced" and manually changed the entry point - but I don't think you want that here. Just telling it to start at WinMain() won't supply all the needed parameters, like HINSTANCE. I think you need to build/link the correct SUBSYSTEM – Mark Stevens Nov 27 '12 at 23:49
  • 1
    The question is how to tell the Qt .pro file to pass that option to the generated Makefile and on to the MS linker. – Mark Stevens Nov 27 '12 at 23:50
  • Actually, I see you're not using any of those WinMain() args - it might be easier to just let it do what it's trying to do and make "_main()" you're entry point. – Mark Stevens Nov 27 '12 at 23:58
  • @MarkStevens well, i forgot to write this in the question (in a rush), but the goal of using WinMain instead of main was so it wouldn't spawn a console. Do you know how to do that in Qt? – Name Nov 28 '12 at 01:57

2 Answers2

2

Delete the statement

CONFIG += console

John Bandela
  • 2,416
  • 12
  • 19
0

I fixed it by making an "Empty Qt Project" instead of a "C++ Console Application"!

Name
  • 2,037
  • 3
  • 19
  • 28