- Online Community Forums » Programming Questions » Having a separate resource loader fails to compile

This thread is locked; no one can reply to it. rss feed Print
Having a separate resource loader fails to compile
Member #14,659
October 2012

I'm trying to write a separate class that loads resources from an archive and passes requested resources back to the caller. My includes, constructor, and image retriever methods are as follows.

1#include <allegro5/allegro.h> 2#include <allegro5/allegro_image.h> 3#include <allegro5/allegro_physfs.h> 4#include <physfs.h> 5#include <string> 6 7ResourceCache::ResourceCache() { 8 PHYSFS_init(NULL); 9 PHYSFS_addToSearchPath("data/", 1); 10 PHYSFS_addToSearchPath("data/", 1); 11 al_init_image_addon(); 12 al_init_acodec_addon(); 13 al_set_physfs_file_interface(); 14} 15 16ALLEGRO_BITMAP *get_image(std::string file) { 17 ALLEGRO_BITMAP *img; 18 std::string filepath = "images/" + file; 19 img = al_load_bitmap(filepath.c_str()); 20 if (!img) return NULL; 21 else return img; 22}

This is the code segment where I retrieve a resource from the class.

ResourceCache res;
img = res.get_image("bg.png");

The compiler fails with

Test.obj : error LNK2019: unresolved external symbol "public: struct ALLEGRO_BITMAP * __thiscall ResourceCache::get_image(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?get_image@ResourceCache@@QAEPAUALLEGRO_BITMAP@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main

The problem is, if I copy the loading functions over to the same file my main function is in, it compiles and displays correctly. The link error only occurs when I'm using the resource loader class. What could be causing the error?

Gabriel Campos
Member #12,034
June 2010

if get_image is a method from ResourceCache class, it appears that u are forgetting to add it before the implementation

ALLEGRO_BITMAP *ResourceCache::get_image()

tell if works.

Member #14,659
October 2012

Yes, that fixed it. Coming from a mainly Java background, it still takes some conscious effort to write class methods this way. Thanks!

Go to: