Why doesn’t __attribute__((constructor)) work in a static library?
The linker does not include the code in foo.a in the final program because nothing in main.o references it. If main.c is rewritten as follows, the program will work: //main.c void foo(); int main() { void (*f)() = foo; return 0; } Also, when compiling with a static library, the order of the arguments to … Read more