我想知道编译器/链接器是否会删除已在公共头文件中的全局变量extern
'd?例如:移除外部全局的死代码
// public.h
struct func_ptrs {
void (*foo)(void);
void (*bar)(int);
};
extern const struct func_ptrs DEFAULT_FUNCS;
和:
// private.c
#include "public.h"
void def_foo(void) { ... }
void def_bar(int a) { ... }
const struct func_ptrs DEFAULT_FUNCS = { .foo = def_foo, .bar = def_bar };
是否有任何特定的链接器标记,将允许该变量(和两个函数)从所得到的二进制剥离?
假定GCC和MSVC作为两个目标编译器。
看看这里:http://stackoverflow.com/questions/6687630/how-to-remove-unused-cc-symbols-with-gcc-and-ld – nsilent22