2

I have been trying to create my own cross platform resource manager for embedding and managing resources. I have however, run into some problems. The idea is that all resources is run through a program which creates a .cpp file, with the content of the resource as an array. My idea was to do this in such a way that, these .cpp only have to build as part of the library to be registered as resources.

I have a singleton class, ResourceManager, which keeps track of embedded resources. I use a class ResourceAutoRegister, of which i use the constructer to register the resources automatically if they get compiled:

ResourceAutoRegister(const std::string & name, const uint8_t * data, const 
size_t data_size)
{
    ResourceManager::getInstance().create_resource(name, data, data_size);
}

This is invoked in the resource files which look similar to this:

static const std::array<uint8_t,41947> ar_picture = {...};
namespace {ResourceAutoRegister autoregpic("Textures/picture.png",ar_picture.data(), ar_picture.size());}

A .cpp file is created for each resource.

This works fine when i do a test application, where the ResourceManager and resources is build as part of an application. However, the idea was to use is as a static library, so the large amount of resources only had to be compiled whenever changes was made to the resources. However, when i do this, the ResourceAutoRegister objects is not constructed.

So the question is, why are these objects not constructed when linked as as a static library to as part of an application? Second, is there any way to ensure that these are constructed, even when build as a library. Judged by the size of the library, the static arrays clearly is present within the library.

MathiasJ
  • 71
  • 7

0 Answers0