[QTCreator] undefined reference to... Linker Problem



  • Hey,

    ich habe ein kleines Problem:

    capplication.h

    #ifndef CAPPLICATION_H
    #define CAPPLICATION_H
    
    #include <windows.h>
    #include <string>
    #include <map>
    #include <sstream>
    #include "cobj.h"
    #include "Base/cproperty.h"
    #include "Base/cstructs.h"
    #include "Base/cconst.h"
    
    class CApplication
    {
    private:
        MSG msg;
    public:
        //functions
        CApplication();
    
        void Close();
        int Execute();
        void Initialize(HINSTANCE hInst, HINSTANCE pInst, PSTR Cmd, int Show);
    
        //variables
        HINSTANCE thisInstance, prevInstance;
        PSTR CmdLine;
        int ShowState;
    
    };
    
    #endif // CAPPLICATION_H
    

    capplication.cpp:

    #include "capplication.h"
    
    CApplication::CApplication()
    {
        //
    }
    
    void CApplication::Initialize(HINSTANCE hInst, HINSTANCE pInst, PSTR Cmd, int Show)
    {
        thisInstance = hInst;
        prevInstance = pInst;
        CmdLine = Cmd;
        ShowState = Show;
    }
    
    void CApplication::Close()
    {
        PostQuitMessage(0);
    }
    
    int CApplication::Execute()
    {
        while (GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    

    main.cpp

    #include <capplication.h>
    
    CApplication app;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
    {
        app.Initialize(hInstance, hPrevInstance, szCmdLine, iCmdShow);
    
        app.Execute();
    
        return 0;
    }
    

    test.pro:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt
    
    INCLUDEPATH += F:\CWinClass_old\class
    
    SOURCES += main.cpp
    

    Fehler:

    F:\CWinClass\Basic\build-test-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\main.o:-1: In function `WinMain@16':
    F:\PX\Basic\main.cpp:9: Fehler: undefined reference to `CApplication::Initialize(HINSTANCE__*, HINSTANCE__*, char*, int)'
    F:\PX\Basic\main.cpp:14: Fehler: undefined reference to `CApplication::Execute()'
    F:\CWinClass\Basic\build-test-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\main.o:-1: In function `_static_initialization_and_destruction_0':
    F:\PX\Basic\main.cpp:4: Fehler: undefined reference to `CApplication::CApplication()'
    

    So, ich binde in der main.cpp die capplication.h ein, die aber in einem anderen Ordner liegt. Diesen Ordner habe ich ja eigentlich richtig in der PRO Datei eigebunden. Aber ich bekomme diese Meldungen, die ich leider nicht nachvollziehen kann. Tipps und HIlfen wären toll 🙂



  • push


  • Mod

    Du musst natürlich auch capplication.cpp in den SOURCEN in deiner pro Datei haben...



  • Wieso das den? Ich Include doch beispielsweie sie windows.h auch einfach so ohne iwas in der PRO stehen zu haben. Mir ist klar, dass es da keine cpp Datei für gibt, ich wollte halt einfach eine Art Library schreiben ohne eine Library zu compilern



  • Frolo1 schrieb:

    Wieso das den? Ich Include doch beispielsweie sie windows.h auch einfach so ohne iwas in der PRO stehen zu haben.

    Dann linkt deine Entwicklungsumgebung die Bibliotheken mit den Funktionen, die in windows.h nur deklariert werden, wohl automatisch dazu.



  • okay dann so: Ich schreibe eine eigene kleine Visual Component Library (Projekt in der Schule) und möchte, dass man diese in neue Projekte einbinden kann ohne wirklich jede C++ Datei in die PRO zu schreiben. Wie mache ich das am geschicktesten? Muss ja irgendwie gehen.

    Danke 🙂



  • Du hast es selbst gesagt: Library.

    Mach eine Bibliothek daraus.



  • und wie geht das? o:


Anmelden zum Antworten