2017-06-30 16:49:15 +02:00
Installation and Integration
============================
2017-03-30 16:56:49 +02:00
SDK
---
2019-03-31 10:15:08 +02:00
For each platform there is an SDK that contains:
2017-03-30 16:56:49 +02:00
* Static library
* Headers
2019-03-31 10:15:08 +02:00
* Examples
2017-03-30 16:56:49 +02:00
2019-03-31 10:15:08 +02:00
Nightly build can be downloaded here: https://lief-project.github.io/packages/sdk while releases are available here: https://github.com/lief-project/LIEF/releases.
2017-03-30 16:56:49 +02:00
Python
------
2019-03-31 10:15:08 +02:00
Since 0.10.0
***** ***** **
To install nightly build (master):
.. code-block :: console
$ pip install [--user] --index-url https://lief-project.github.io/packages lief
Python packages can be found here: https://lief-project.github.io/packages/lief
2017-07-25 17:06:30 +02:00
2019-03-31 10:15:08 +02:00
To install **release** package
.. code-block :: console
2017-07-25 17:06:30 +02:00
2019-03-31 10:15:08 +02:00
$ pip install lief
Release packages can be found here: `Releases <https://github.com/lief-project/LIEF/releases> `_
Using `` setup.py `` , one can build and install lief as follows:
2017-07-25 17:06:30 +02:00
.. code-block :: console
2019-03-31 10:15:08 +02:00
$ python ./setup.py [--user] install
2017-07-25 17:06:30 +02:00
2019-03-31 10:15:08 +02:00
From 0.8.0 to 0.9.0
***** ***** ***** *** *
2017-07-25 17:06:30 +02:00
To install **release** package
.. code-block :: console
$ pip install pylief-VERSION.zip
Release packages can be found here: `Releases <https://github.com/lief-project/LIEF/releases> `_
Before 0.8.0
***** ***** **
2017-03-30 16:56:49 +02:00
To install the Python API (example with `` Python 3.5 `` ):
.. code-block :: console
$ pip install lief-XX.YY.ZZ_py35.tar.gz
2017-06-30 16:49:15 +02:00
Visual Studio Integration
-------------------------
2017-04-06 15:08:06 +02:00
The pre-built SDK is compiled in release configuration with the *Multi-threaded* runtime library.
As example we compile the following snippet with Visual Studio 2015
.. code-block :: cpp
#include "stdafx.h"
#include <LIEF/LIEF.hpp>
int main()
{
2019-07-08 08:40:10 +02:00
std::unique_ptr<LIEF::PE::Binary> pe_binary = LIEF::PE::Parser::parse("C:\\Windows\\explorer.exe");
2017-04-06 15:08:06 +02:00
std::cout << *pe_binary << std::endl;
return 0;
}
First the build type must be set to `` Release `` :
.. figure :: _static/windows_sdk/s1.png
:align: center
Build type set to `` Release ``
Then we need to specify the location of the LIEF include directory:
.. figure :: _static/windows_sdk/s2.png
:align: center
LIEF include directory
and the location of the `` LIEF.lib `` library:
.. figure :: _static/windows_sdk/s5.png
:align: center
LIEF library
As `` LIEF.lib `` was compiled with the `` \MT `` flag we have to set it:
.. figure :: _static/windows_sdk/s3.png
:align: center
*Multi-threaded* as runtime library
LIEF makes use of `` and, or, not `` C++ keywords. As **MSVC** doesn't support these keywords by default, we need to add the special file `` iso646.h `` :
.. figure :: _static/windows_sdk/s4.png
:align: center
2017-06-30 16:49:15 +02:00
Add `` iso646.h `` file
2017-04-06 15:08:06 +02:00
2017-06-30 16:49:15 +02:00
XCode Integration
-----------------
2017-04-06 15:08:06 +02:00
2017-06-30 15:41:52 +02:00
To integrate LIEF within a XCode project, one needs to follow these steps:
2017-04-06 15:08:06 +02:00
2017-06-30 15:41:52 +02:00
First we create a new project:
2017-03-30 16:56:49 +02:00
2017-06-30 15:41:52 +02:00
.. figure :: _static/xcode_integration/step1.png
:align: center
New Project
For this example we select a *Command Line Tool* :
.. figure :: _static/xcode_integration/step2.png
:align: center
Command Line Tool
.. figure :: _static/xcode_integration/step3.png
:align: center
Project options
Then we need to add the static library `` libLIEF.a `` or the shared one (`` libLIEF.dylib `` )
.. figure :: _static/xcode_integration/step4.png
:align: center
Project configuration - Build Phases
.. figure :: _static/xcode_integration/step5.png
:align: center
Project configuration - Build Phases
.. figure :: _static/xcode_integration/step6.png
:align: center
Project configuration - Build Phases
In the `Build Settings - Search Paths` one needs to specify the paths to the **include directory** and to location of the LIEF libraries (`` libLIEF.a `` and/or `` libLIEF.dylib `` )
.. figure :: _static/xcode_integration/step7.png
:align: center
Libraries and Include search paths
Once the new project configured we can use LIEF:
.. figure :: _static/xcode_integration/code.png
:align: center
Source code
and run it:
.. figure :: _static/xcode_integration/result.png
:align: center
2017-03-30 16:56:49 +02:00
2017-06-30 15:41:52 +02:00
Output
2017-03-30 16:56:49 +02:00
2017-06-30 16:49:15 +02:00
CMake Integration
-----------------
2017-03-30 16:56:49 +02:00
2017-07-19 15:46:37 +02:00
External Project
***** ***** ***** *
Using `CMake External Project <https://cmake.org/cmake/help/v3.0/module/ExternalProject.html> `_ :
.. literalinclude :: _static/CMakeExternalProject.cmake
:language: cmake
:lines: 1-42
2017-06-30 16:49:15 +02:00
And now, to be integrated within a project:
2017-07-19 15:46:37 +02:00
.. literalinclude :: _static/CMakeExternalProject.cmake
:language: cmake
:lines: 47-
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
For the compilation:
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
.. literalinclude :: _static/ReadmeExternalProject.rst
:language: rst
:lines: 1-42
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
A *full* example is available in the `` examples/cmake/external_project `` directory.
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
find_package()
***** ***** *** *
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
Using `CMake find_package() <https://cmake.org/cmake/help/v3.0/command/find_package.html> `_ :
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
.. literalinclude :: _static/CMakeFindPackage.cmake
:language: cmake
:lines: 5-19
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
And now, to be integrated within a project:
.. literalinclude :: _static/CMakeFindPackage.cmake
:language: cmake
:lines: 20-
For the compilation:
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
.. literalinclude :: _static/ReadmeFindPackage.rst
:language: rst
2017-06-30 16:49:15 +02:00
2017-07-19 15:46:37 +02:00
A *full* example is available in the `` examples/cmake/find_package `` directory.