Link-Fehler LNK2001: unresolved external symbol



  • Hallo!

    Ich bin zurzeit dabei eine Klasse zu schreiben, die alle globalen Informationen speichert. Dies funktionert auch mit Integer-Werten oder Strings ohne Probleme. Leider scheint es mit Maps nicht zu funktionieren. Hier bekomme ich immer Linker-Fehler, egal ob ich GCC oder VC verwende. Was mache ich falsch?

    Viele Grüße
    pmw

    #ifndef GLOBALSETTINGS_H
    #define GLOBALSETTINGS_H
    
    #include <string>
    #include <map>
    #include <climits>
    
    using namespace std;
    
    struct CGlobalSettings
    {
    
    	static const long iMinBuffer;
    	static const long iMaxBuffer;
    
    	static map<string, string> mssConfig; // <-- Findet Linker nicht
    
    };
    
    void LoadDefaultMessages();
    
    #endif
    
    #include "globalsettings.h"
    
    const long CGlobalSettings::iMinBuffer = 1024;
    const long CGlobalSettings::iMaxBuffer = (LONG_MAX - 1);
    
    void LoadDefaultMessages()
    {
    
    	CGlobalSettings::mssConfig["FatalError"] = "Fatal Error:";
    	CGlobalSettings::mssConfig["CannotFind"] = "Cann't open file \"%s\".";
    
    }
    
    #include <iostream>
    #include <string>
    #include <map>
    
    #include "globalsettings.h"
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    
    	LoadDefaultMessages();
    
    	cout << CGlobalSettings::iMaxBuffer << endl;
    	cout << "[Language]=(" << CGlobalSettings::mssConfig["Language"] << ")" << endl;
    
    	getchar();
    	return 0;
    
    }
    
    Linking...
    globalsettings.obj : error LNK2001: unresolved external symbol "public: static class std::map<class std:: [...]
    main.obj : error LNK2019: unresolved external symbol "public: static class std::map<class std::basic_string [...]
    console.exe : fatal error LNK1120: 1 unresolved externals
    


  • Hallo

    du must wie bei den anderen static-membern auch die Map noch implementieren.

    #include "globalsettings.h"
    
    const long CGlobalSettings::iMinBuffer = 1024;
    const long CGlobalSettings::iMaxBuffer = (LONG_MAX - 1);
    map<string, string> CGlobalSettings::mssConfig; // hinzufügen
    ...
    

    bis bald
    akari



  • Hallo akari,

    vielen dank für deine schnelle Antwort. Wie konnte ich nur das nur übersehen 😞 Ich habe wirklich ewig lang überlegt und geknobelt. Irgendwann wird man Betriebsblind. Auf jeden Fall vielen Dank für deine Hilfe!

    Viele Grüße
    pmw


Anmelden zum Antworten