简体   繁体   中英

Does stripping all symbols from a static library prevent linking?

As far as I know, the linker's job is to match undefined symbols in an object file with symbols defined in a static library. If found, the proper symbol definition is included into the final executable. This is the so-called symbol resolution.

So what happens if all symbols get stripped away from the static library? Does it prevent the linker to resolve symbols correctly?

Stripping symbols is an operation that's normally meant to remove debug information on symbols, not symbols needed for the actual linking process (though it can be used to remove symbols for things that you don't want used in the linking process if, for example, you didn't generate the object file).

It would be a rather bad use of the tool were it to render libraries or object file useless for linking.

Don't get me wrong, you can actually do this with, for example, strip --strip-all , it's just not a sensible thing to do. For example, consider the files prog1.c and prog2.c :

// prog1.c
int fn(void);
int main(void) { return fn(); }

// prog2.c
int fn(void) { return 42; }

Running the following commands on these files:

gcc -o prog1.o -c prog1.c
gcc -o prog2.o -c prog2.c
strip --strip-all prog2.o
gcc -o prog prog1.o prog2.o

will result in a linker error because it cannot find fn() - it's been stripped from prog2.o . However, executing the same commands except for the strip will work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM