My goal is to generate a *.dll that contains all the resources the program needs (around 5 Mo worth of data). I use a program of my own that converts all the files in a folder into a big .hpp such as:
#pragma once
#include <vector>
#include <map>
#include <string>
std::map<std::string, std::vector<uint8_t>> assets {
{"file_A.md", {
0x23, 0x20, 0x2A, 0x2A, 0x43, 0x6F, 0x6E, 0x74, 0x72, 0xC3, 0xB4, 0x6C, 0x65, 0x72, 0x20, 0x6C,
0x27, 0x61, 0x73, 0x70, 0x65, 0x63, 0x74, 0x20, 0x67, 0xC3, 0xA9, 0x6E, 0xC3, 0xA9, 0x72, 0x61}},
{"file_B.md", {
0x24, 0x20, 0x2A, 0x2A, 0x43, 0x6F, 0x6E, 0x74, 0x72, 0xC3, 0xB4, 0x6C, 0x65, 0x72, 0x20, 0x6C,
0x27, 0x61, 0x73, 0x70, 0x65, 0x63, 0x74, 0x20, 0x67, 0xC3, 0xA9, 0x6E, 0xC3, 0xA9, 0x72, 0x61}},
...
...
};
Then I include this file into another project and use the map to iterate through the files.
When the size of the binaries converted are above around 500ko, mvsc 2019 (driven by CMake) crashes with the message :
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(687,5): error MSB6006: Arrêt de "CL.exe" avec le code -1073741571. [C:\GitHub\gtb-visual-control-template\build\gtb-visual-control-template.vcxproj]
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/GitHub/gtb-visual-control-template/build --config Debug --target ALL_BUILD -j 10 -- exited with code: 1
[build] Build finished with exit code 1
What could be the cause of the problem? Is it related to the type of structure I am using for holding the data ?
Whenever you use list initialization syntax (curly braces) to initialize an object that has a real constructor in it, that constructor call has to take an
initializer_list. Thatinitializer_listobject points to an array of values which must exist somewhere. And that "somewhere" tends to be on a stack at some point.So you need to make sure that the braced-init-list does not have so many values that it won't fit onto the stack.
So instead of directly initializing the
mapwith that much data, you need to initialize a static C++ array type, and then use that to initialize themap.