Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (1 / 5) |
Uptime: | 18:40:29 |
Calls: | 629 |
Files: | 1,186 |
D/L today: |
19 files (29,897K bytes) |
Messages: | 167,605 |
I don't think this is a pure C programming question, but it's related.
I'm building a static library mylib.a with all the object files except main.o, and the final executable linking together main.o and mylib.a.
I want to remove from the final exe everything present in mylib.a that
is not used in main.o.
Suppose only mod1.o is present in mylib.a. foo1() and bar1() are defined
in mod1.c. main() is the only function in main.c and only foo1() is
called from main().
gcc -O2 -ffunction-sections -fdata-sections -c -o mod1.o mod1.c
ar rcs mylib.a mod1.o
gcc -O2 -ffunction-sections -fdata-sections -c -o main.o main.c
gcc -Wl,--gc-sections,--print-gc-sections -o main[.exe] main.o mylib.a objdump -d main[.exe] | grep bar1
MinGW in Windows build a main.exe that contains bar1(), while gcc in WSL doesn't.
Why?