回答我自己的问题:最后我们采用了匿名命名空间和代码合并。
即所有cpp/c 代码都使用一个大且相对复杂/丑陋的python 脚本合并到大C 文件中。CPP 文件中的所有函数都包装在一个匿名命名空间中,只将导出的函数留在命名空间之外。
之后在库上执行 strip -S -x 清除了大部分垃圾。
IE
/************** AMALGAMATED CPP FILE **************/
/************** STD HEADERS **************/
#include "OurLibraryHeader.h"
#include <cmath>
#include <string>
// more standard includes here and includes that aren't possible to do in the anonymous namespace
/************** AMALGAM **************/
namespace {
#include "OneofOurheaders1.h"
#include "OneofOurheaders2.h"
#include "SomeExternalLib.h"
/************************* OneofOurImplementations.cpp *************************/
// included literally
/************************* OneofOurImplementations2.cpp *************************/
// included literally
// etc
}
int OneOfOurLibraryFunctions()
{
}
// etc
这是相当肮脏的,但它可以完成工作。我确信有一些更好的方法可以通过一些 LLVM 技巧来做到这一点......