问题
I need to parse the loadable parts of an ELF executable for a simple loader. Found the nice "libelf by Example" tutorial (by J. Koshy) that gives a nice overview on the structure of an ELF. It then lead me to the ELF Toolchain project, which implements, among other things, the libelf
library of ELF handling functions.
The nice thing about using this library is that it encapsulates the variations in ELF formats and makes the code more portable and future proof. However, I found out that in order to be able to build the package on Ubuntu, I needed to install a great amount of prerequisites.
I tried to build only the libelf part by running pmake
in the libelf directory, but got a build error complaining on missing header file - which is apparently automatically generated by the global make process and is architecture dependent.
My question is - how can I build just the libelf
part of ELF Toolchain?
回答1:
You can build select parts of the Elftoolchain source tree by commenting out the appropriate SUBDIR
lines in the top-level Makefile
.
For building libelf
, you should be able to get by with the following two directories:
% grep ^SUBDIR Makefile | head -2
SUBDIR += common
SUBDIR += libelf
Note: On Ubuntu, you could also use GNU libelf, which offers a different implementation of the same API, and for which there appears to be ready-made packages.
来源:https://stackoverflow.com/questions/19065062/elftoolchain-how-to-build-the-libelf-library-w-o-the-rest-of-the-package