I've been trying to make something where I can just plug-in a new implementation (for things like opening a window, displaying graphics, etc.) and it work just like before. I've added a couple of other things like a resource manager, but now I'm getting linker errors. This didn't happen until I tried to do what the IDE calls 'Clean All Targets' (which I think is a complete rebuild?).

Currently, it gives me several ' "..." referenced from: ...' errors, which to me looks like it's complaining about no definition of the constructor, destructor, and a function called 'SetFilename' (Which are defined in the .cpp file). All of the classes it complains about are templated from one called 'Resource'.

At the end is 'Symbol(s) not found' and 'collect2: ld returned 1 exit status'.

I thought it should compile just fine (Whether it works or not, who knows! :P), but that obviously isn't working out too well...

The header of the class that is giving the problems:

#ifndef BGE_RESOURCE_H
#define BGE_RESOURCE_H

#include <string>

namespace bge
{
    template < class T >
    class Resource
    {
    public:
        Resource();
        Resource( const std::string& name );
        ~Resource();
        
        void SetFilename( const std::string& name );
        const std::string& GetFilename() const;
        
        bool Load();
        void Unload();
        bool IsLoaded() const;
        
        const T* const GetResource();
        void ReturnResource();
        
    private:
        T* resource;
        unsigned int usedAmount;
        bool loaded;
        std::string filename;
    };
    
    class IFont;
    class IImage;
    class IMusic;
    class ISound;
    
    typedef Resource< IFont >  FontResource;
    typedef Resource< IImage > ImageResource;
    typedef Resource< IMusic > MusicResource;
    typedef Resource< ISound > SoundResource;
}

#endif // BGE_RESOURCE_H

I have no idea how to fix this... Any ideas?

>>'Clean All Targets' (which I think is a complete rebuild?).

No it doesn't mean that. Clean means to just delete all the files that are generated by the compiler, such as *.obj, *.o, *.lib, *.dll, *.pch, etc.

>>'Clean All Targets' (which I think is a complete rebuild?).

No it doesn't mean that. Clean means to just delete all the files that are generated by the compiler, such as *.obj, *.o, *.lib, *.dll, *.pch, etc.

That makes sense, I guess.

If it removes the files, does that mean the symbols used to be in the files, but after deleting the old files, the new files (after recompiling) didn't have it?

The definitions are still in the file they were in before, though. How come they suddenly "disappeared" and aren't getting recompiled with the rest of the functions?

I don't know the answeres to those questions. I'd need the entire program so that I can compile/check it myself.

The only files needed to reproduce it are right here.

(I realize that int main() and most of the functions in ResourceManager are empty.)

Thanks for taking a look at it!

VC++ 2010 Express errors

1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall bge::Resource<class bge::IFont>::SetFilename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SetFilename@?$Resource@VIFont@bge@@@bge@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddFont(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddFont@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IFont>::~Resource<class bge::IFont>(void)" (??1?$Resource@VIFont@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddFont(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddFont@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IFont>::Resource<class bge::IFont>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$Resource@VIFont@bge@@@bge@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddFont(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddFont@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall bge::Resource<class bge::IImage>::SetFilename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SetFilename@?$Resource@VIImage@bge@@@bge@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IImage>::Resource<class bge::IImage>(void)" (??0?$Resource@VIImage@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IImage>::~Resource<class bge::IImage>(void)" (??1?$Resource@VIImage@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IImage>::Resource<class bge::IImage>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$Resource@VIImage@bge@@@bge@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall bge::Resource<class bge::ISound>::SetFilename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SetFilename@?$Resource@VISound@bge@@@bge@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddSound(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddSound@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::ISound>::~Resource<class bge::ISound>(void)" (??1?$Resource@VISound@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddSound(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddSound@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::ISound>::Resource<class bge::ISound>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$Resource@VISound@bge@@@bge@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddSound(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddSound@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall bge::Resource<class bge::IMusic>::SetFilename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SetFilename@?$Resource@VIMusic@bge@@@bge@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddMusic(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddMusic@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IMusic>::~Resource<class bge::IMusic>(void)" (??1?$Resource@VIMusic@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddMusic(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddMusic@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IMusic>::Resource<class bge::IMusic>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$Resource@VIMusic@bge@@@bge@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddMusic(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddMusic@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>C:\dvlp\unmanaged\test1\Debug\test1.exe : fatal error LNK1120: 13 unresolved externals

That means you have not coded the implementation of those functions. They are declared in resource.h but are not implemented in resource.cpp or resource.h. I think I would just make them inline functions in resource.h void SetFilename( const std::string& name ) { this->filenae = name;} The implementation code for most templates is normally in the header file, not a *.cpp file.

Weird, the implementation shows up in the .cpp file on my computer.

Anyways, I moved it to the header, and it works. Thank you for the help! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.