Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22080

How to build relocatable binary which includes only selected symbols from libraries?

$
0
0

I am trying to build a relocatable binary file for an embedded system which includes only some libraries. It will not include any source file, just the libraries will be linked into a relocatable file as follows:

ld -r -o <binary_name> --whole-archive <list of libraries>

If I do not use the --whole-archive option, then the resulting binary file does not contain any symbols because, I am not linking any object files which will use the symbols. So, I am using the --whole-archive and the binary file is generated successfully.

Now, I want to reduce the size of the binary file. I have only few apps on my embedded system, and so, I know exactly which symbols from the list of libraries will be used by my apps. So, while linking, I want to include only this set of symbols in the final binary file.

For example, suppose I am trying to link libc into a relocatable binary file. And suppose, my application will use only printf symbol from libc, then I want my relocatable binary to contain only printf and any symbols used by printf.

Is there any way to achieve this?


Viewing all articles
Browse latest Browse all 22080

Trending Articles