Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

04.07.2016, 21:27

[gelöst] Undefined Reference to `Core::Core()'

Abend,

habe folgenden Code geschrieben.

main.cpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
#include <iostream>
#include "core.hpp"

int main() {
    Core core;
    core.Run();
    return 0;
}


core.cpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "core.hpp"

const sf::Time Core::TimePerFrame = sf::seconds(1.f / 60.f);

Core::Core() 
:Application(sf::VideoMode(800, 480, 32), "Projekt 1 - Uebung", sf::Style::Default) {
    if (!m_TextFont.loadFromFile("media/fonts/tahoma.ttf")) {
        throw std::runtime_error("Failed to load 'tahoma.ttf' in Main-Core!");
    }
    else {
        m_StatisticsText.setFont(m_TextFont);
        m_StatisticsText.setColor(sf::Color::Red);
        m_StatisticsText.setCharacterSize(10);
        m_StatisticsText.setPosition(1.f, 1.f);
    }

}

Core::~Core() {

}

void Core::Run() {
    sf::Clock clock;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;

    while (Application.isOpen()) {
        ProcessEvents();
        Update(timeSinceLastUpdate);
        UpdateStatistics(timeSinceLastUpdate);
        Render();

        sf::Time waitTime = TimePerFrame - timeSinceLastUpdate;
        sf::sleep(waitTime);

        timeSinceLastUpdate = clock.restart();
    }
}

void Core::Update(sf::Time deltatime) {

}

void Core::UpdateStatistics(sf::Time elapsedTime) {
    m_StitisticsUpdateTime += elapsedTime;
    m_StatisticsNumFrame++;

    if (m_StitisticsUpdateTime >= sf::seconds(1.f)){
        m_StatisticsText.setString("Frames: " + std::to_string(m_StatisticsNumFrame) + "\n" +
            "Time/Update: " + std::to_string(m_StitisticsUpdateTime.asMicroseconds() / m_StatisticsNumFrame));

        m_StitisticsUpdateTime -= sf::seconds(1.f);
        m_StatisticsNumFrame = 0;
    }
}

void Core::ProcessEvents(){
    while (Application.pollEvent(Event)) {
        if (Event.type == sf::Event::Closed) {
            Application.close();
        }
    }
}

void Core::Render(){
    Application.clear();
    Application.draw(m_StatisticsText);
    Application.display();
}


core.hpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once
#include <SFML/Graphics.hpp>

class Core {

public:
    Core();
    ~Core();

    void Run();

    sf::RenderWindow Application;
    sf::Event Event;

private:
    void Update(sf::Time deltatime);
    void UpdateStatistics(sf::Time elapsedTime);
    void ProcessEvents();
    void Render();

    sf::Font m_TextFont;
    sf::Text m_StatisticsText;
    sf::Time m_StitisticsUpdateTime;
    std::size_t m_StatisticsNumFrame;
    static const sf::Time TimePerFrame;
};


Nun bekomme ich auf dem Raspberry Pi unter RASPBIAN JESSIE immer folgenden Fehler Code beim erstellen.

Quellcode

1
2
3
4
5
main.o: In function `main':
main.cpp:(.text+0x14): undefined reference to `Core::Core()'
main.cpp:(.text+0x20): undefined reference to `Core::Run()'
main.cpp:(.text+0x30): undefined reference to `Core::~Core()'
main.cpp:(.text+0x44): undefined reference to `Core::~Core()'


Leider kann ich mir nicht zusammenreimen was der Fehler ist! Hab ich eventuell die core.hpp falsch included?

Gruß PSP3004

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »psp3004« (04.07.2016, 21:54)


2

04.07.2016, 21:28

Hast du core.cpp auch kompiliert und dazugelinkt?

3

04.07.2016, 21:46

Kompiliert natürlich, nur nicht dazugelinkt :dash: :whistling: :D
trotzdem danke für die schnelle Antwort.

PS:
Kann man hier eigentlich angeben ob das Problem gelöst worden ist. Also als den Betrag als gelöst markieren?

4

04.07.2016, 21:47

Editiere einfach deinen Eingangspost und setze '[gelöst]' oä. vor den Titel.

Werbeanzeige