My work place is developing code for some absolutely ancient hardware that doesn’t have virtual memory. Because of this we’re trying to be careful to minimize the text size of object and binary files, so we don’t run out of memory. This likely means we’ll need to limit the use of templates from the STL, or ban them outright. While looking around to find a way to minimize the size of our files, and still use templates, I came across the -frepo option for g++. A few tests later, I’m even more confused than when I started. The final binary file is the same size or larger when the -frepo is used, which doesn’t make sense from me. Can anyone explain to me what this option actually does (other than “it just works,” as that’s the explanation from the GCC 4.7.1 manual) and how I might be abusing it?
Compiling with g++ -c -frepo main.cpp test8.cpp and linking with g++ test8.o main.o
The .rpo files arebeing created.
test8.h:
#include <list>
using namespace std;
class Test
{
public:
Test ();
list<int> makeNewIntList ();
private:
list<int> intList;
};
test8.cpp:
#include "test8.h"
#include <list>
using namespace std;
Test::Test()
{
intList = list<int>( 10, 12 );
}
list<int> Test::makeNewIntList()
{
intList.push_back(4);
return intList;
}
main.cpp
#include "test8.h"
using namespace std;
void findFive (int num);
list<int> makeIntList();
int main( int argc, char* argv[])
{
Test test;
list<int> intList = test.makeNewIntList();
list<int> intList2 = makeIntList();
list<float> floatList = list<float> (10,12);
floatList.push_back(5);
}
list<int> makeIntList()
{
list<int> intList = list<int> (10,12);
return intList;
}
We are using GCC 4.1.2. Also note GCC 4.7.0 isn’t much better, and upgrading the compiler isn’t a viable solution.
I would advise that you forget about
-frepo, it’s a relic and hardly used.Instead you could look at the
extern templatesyntax for declaring explicit instantiations, to prevent templates being instantiated implicitly, allowing you to control the instantiations so they only happen in one place. To be sure you don’t miss any you could also compile with-fno-implicit-templates(which isn’t necessary if you’re rigorous about usingextern templatedeclarations everywhere necessary.)