"vscode:/vscode.git/clone" did not exist on "204fa9cf7d67d6da9908493a78e7b52980c4bb23"
Installation-Guide.rst 27 KB
Newer Older
1
2
3
Installation Guide
==================

4
This is a guide for building the LightGBM Command Line Interface (CLI). If you want to build the Python-package or R-package please refer to `Python-package`_ and `R-package`_ folders respectively.
5

6
7
8
All instructions below are aimed at compiling the 64-bit version of LightGBM.
It is worth compiling the 32-bit version only in very rare special cases involving environmental limitations.
The 32-bit version is slow and untested, so use it at your own risk and don't forget to adjust some of the commands below when installing.
9

10
11
If you need to build a static library instead of a shared one, you can add ``-DBUILD_STATIC_LIB=ON`` to CMake flags.

12
Users who want to perform benchmarking can make LightGBM output time costs for different internal routines by adding ``-DUSE_TIMETAG=ON`` to CMake flags.
Guolin Ke's avatar
Guolin Ke committed
13

14
It is possible to build LightGBM in debug mode. In this mode all compiler optimizations are disabled and LightGBM performs more checks internally. To enable debug mode you can add ``-DUSE_DEBUG=ON`` to CMake flags or choose ``Debug_*`` configuration (e.g. ``Debug_DLL``, ``Debug_mpi``) in Visual Studio depending on how you are building LightGBM.
Guolin Ke's avatar
Guolin Ke committed
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.. _sanitizers:

In addition to the debug mode, LightGBM can be built with compiler sanitizers.
To enable them add ``-DUSE_SANITIZER=ON -DENABLED_SANITIZERS="address;leak;undefined"`` to CMake flags.
These values refer to the following supported sanitizers:

- ``address`` - AddressSanitizer (ASan);
- ``leak`` - LeakSanitizer (LSan);
- ``undefined`` - UndefinedBehaviorSanitizer (UBSan);
- ``thread`` - ThreadSanitizer (TSan).

Please note, that ThreadSanitizer cannot be used together with other sanitizers.
For more info and additional sanitizers' parameters please refer to the `following docs`_.
It is very useful to build `C++ unit tests <#build-c-unit-tests>`__ with sanitizers.

31
32
.. _nightly-builds:

33
You can also download the artifacts of the latest successful build on master branch (nightly builds) here: |download artifacts|.
34

35
36
37
38
.. contents:: **Contents**
    :depth: 1
    :local:
    :backlinks: none
39

40
41
42
Windows
~~~~~~~

43
44
45
46
On Windows LightGBM can be built using

- **Visual Studio**;

47
- **CMake** and **VS Build Tools**;
48
49

- **CMake** and **MinGW**.
50

51
52
Visual Studio (or VS Build Tools)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53
54
55
56

With GUI
********

57
1. Install `Visual Studio`_ (2015 or newer).
58

59
2. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
60
61
62

3. Go to ``LightGBM-master/windows`` folder.

63
4. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release`` configuration and click ``BUILD`` -> ``Build Solution (Ctrl+Shift+B)``.
64

65
   If you have errors about **Platform Toolset**, go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
66

67
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release`` folder.
68
69
70
71

From Command Line
*****************

72
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
73
74
75

2. Run the following commands:

76
   .. code:: console
77

78
     git clone --recursive https://github.com/microsoft/LightGBM
79
     cd LightGBM
80
81
     cmake -B build -S . -A x64
     cmake --build build --target ALL_BUILD --config Release
82

83
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
84

85
86
MinGW-w64
^^^^^^^^^
87
88
89
90
91

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

92
   .. code:: console
93

94
     git clone --recursive https://github.com/microsoft/LightGBM
95
     cd LightGBM
96
97
     cmake -B build -S . -G "MinGW Makefiles"
     cmake --build build -j4
98

99
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
100

101
**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles"`` one more time if you encounter the ``sh.exe was found in your PATH`` error.
102

103
It is recommended that you use **Visual Studio** since it has better multithreading efficiency in **Windows** for many-core systems
104
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).
105
106

Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
107

108
109
110
Linux
~~~~~

111
On Linux LightGBM can be built using **CMake** and **gcc** or **Clang**.
112

113
1. Install `CMake`_.
114

115
116
2. Run the following commands:

117
   .. code:: sh
118

119
120
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
121
122
     cmake -B build -S .
     cmake --build build -j4
123

124
**Note**: glibc >= 2.28 is required.
125

126
127
**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

128
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
129

130
131
132
133
134
135
136
137
138
Using ``Ninja``
^^^^^^^^^^^^^^^

On Linux, LightGBM can also be built with `Ninja <https://ninja-build.org/>`__ instead of ``make``.

.. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
139
140
     cmake -B build -S . -G 'Ninja'
     cmake --build build -j2
141

142
143
macOS
~~~~~
144

145
On macOS LightGBM can be installed using **Homebrew**, or can be built using **CMake** and **Apple Clang** or **gcc**.
146
147
148

Apple Clang
^^^^^^^^^^^
fanliwen's avatar
fanliwen committed
149

150
Only **Apple Clang** version 8.1 or higher is supported.
fanliwen's avatar
fanliwen committed
151

152
153
154
Install Using ``Homebrew``
**************************

155
.. code:: sh
156
157
158
159
160
161

  brew install lightgbm

Build from GitHub
*****************

162
1. Install `CMake`_ :
Nikita Titov's avatar
Nikita Titov committed
163

164
   .. code:: sh
Nikita Titov's avatar
Nikita Titov committed
165

166
     brew install cmake
fanliwen's avatar
fanliwen committed
167

168
2. Install **OpenMP**:
fanliwen's avatar
fanliwen committed
169

170
   .. code:: sh
fanliwen's avatar
fanliwen committed
171
172

     brew install libomp
173
174
175

3. Run the following commands:

176
   .. code:: sh
177

178
179
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
180
181
     cmake -B build -S .
     cmake --build build -j4
fanliwen's avatar
fanliwen committed
182

183
184
gcc
^^^
185

186
1. Install `CMake`_ :
187

188
   .. code:: sh
189

190
     brew install cmake
191

192
2. Install **gcc**:
193

194
   .. code:: sh
195

196
197
198
199
     brew install gcc

3. Run the following commands:

200
   .. code:: sh
201

202
203
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
204
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
205
206
     cmake -B build -S .
     cmake --build build -j4
207

208
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
209

210
211
212
Docker
~~~~~~

213
Refer to `Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker>`__.
214

215
216
217
218
Build Threadless Version (not Recommended)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The default build version of LightGBM is based on OpenMP.
219
You can build LightGBM without OpenMP support but it is **strongly not recommended**.
220
221
222
223

Windows
^^^^^^^

224
On Windows a version of LightGBM without OpenMP support can be built using
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

- **Visual Studio**;

- **CMake** and **VS Build Tools**;

- **CMake** and **MinGW**.

Visual Studio (or VS Build Tools)
*********************************

With GUI
--------

1. Install `Visual Studio`_ (2015 or newer).

240
2. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
241
242
243
244
245
246
247
248
249
250
251

3. Go to ``LightGBM-master/windows`` folder.

4. Open ``LightGBM.sln`` file with **Visual Studio**.

5. Go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``C/C++`` -> ``Language`` and change the ``OpenMP Support`` property to ``No (/openmp-)``.

6. Get back to the project's main screen, then choose ``Release`` configuration and click ``BUILD`` -> ``Build Solution (Ctrl+Shift+B)``.

   If you have errors about **Platform Toolset**, go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.

252
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release`` folder.
253
254
255
256

From Command Line
-----------------

257
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
258
259
260

2. Run the following commands:

261
   .. code:: console
262

263
     git clone --recursive https://github.com/microsoft/LightGBM
264
     cd LightGBM
265
266
     cmake -B build -S . -A x64 -DUSE_OPENMP=OFF
     cmake --build build --target ALL_BUILD --config Release
267

268
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
269
270
271
272
273
274
275
276

MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

277
   .. code:: console
278

279
     git clone --recursive https://github.com/microsoft/LightGBM
280
     cd LightGBM
281
282
     cmake -B build -S . -G "MinGW Makefiles" -DUSE_OPENMP=OFF
     cmake --build build -j4
283

284
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
285

286
**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles" -DUSE_OPENMP=OFF`` one more time if you encounter the ``sh.exe was found in your PATH`` error.
287
288
289
290

Linux
^^^^^

291
On Linux a version of LightGBM without OpenMP support can be built using **CMake** and **gcc** or **Clang**.
292
293
294
295
296

1. Install `CMake`_.

2. Run the following commands:

297
   .. code:: sh
298

299
300
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
301
302
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
303
304
305
306
307
308

**Note**: glibc >= 2.14 is required.

macOS
^^^^^

309
On macOS a version of LightGBM without OpenMP support can be built using **CMake** and **Apple Clang** or **gcc**.
310
311
312
313
314
315

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

316
1. Install `CMake`_ :
317

318
   .. code:: sh
319
320
321
322
323

     brew install cmake

2. Run the following commands:

324
   .. code:: sh
325

326
327
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
328
329
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
330
331
332
333

gcc
***

334
1. Install `CMake`_ :
335

336
   .. code:: sh
337
338
339
340
341

     brew install cmake

2. Install **gcc**:

342
   .. code:: sh
343
344
345
346
347

     brew install gcc

3. Run the following commands:

348
   .. code:: sh
349

350
351
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
352
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
353
354
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
355

356
357
358
Build MPI Version
~~~~~~~~~~~~~~~~~

359
360
The default build version of LightGBM is based on socket. LightGBM also supports MPI.
`MPI`_ is a high performance communication approach with `RDMA`_ support.
361

362
If you need to run a distributed learning application with high performance communication, you can build the LightGBM with MPI support.
363
364
365
366

Windows
^^^^^^^

367
On Windows an MPI version of LightGBM can be built using
368
369
370

- **MS MPI** and **Visual Studio**;

371
- **MS MPI**, **CMake** and **VS Build Tools**.
372

373
374
375
With GUI
********

376
1. You need to install `MS MPI`_ first. Both ``msmpisdk.msi`` and ``msmpisetup.exe`` are needed.
377

378
2. Install `Visual Studio`_ (2015 or newer).
379

380
3. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
381
382
383

4. Go to ``LightGBM-master/windows`` folder.

384
5. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release_mpi`` configuration and click ``BUILD`` -> ``Build Solution (Ctrl+Shift+B)``.
385

386
   If you have errors about **Platform Toolset**, go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
387

388
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release_mpi`` folder.
389
390
391
392

From Command Line
*****************

393
1. You need to install `MS MPI`_ first. Both ``msmpisdk.msi`` and ``msmpisetup.exe`` are needed.
394

395
2. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
396
397
398

3. Run the following commands:

399
   .. code:: console
400

401
     git clone --recursive https://github.com/microsoft/LightGBM
402
     cd LightGBM
403
404
     cmake -B build -S . -A x64 -DUSE_MPI=ON
     cmake --build build --target ALL_BUILD --config Release
405

406
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
407

408
**Note**: Building MPI version by **MinGW** is not supported due to the miss of MPI library in it.
409
410
411
412

Linux
^^^^^

413
On Linux an MPI version of LightGBM can be built using **Open MPI**, **CMake** and **gcc** or **Clang**.
414

415
1. Install `Open MPI`_.
416

417
2. Install `CMake`_.
418

419
420
3. Run the following commands:

421
   .. code:: sh
422

423
424
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
425
426
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
427
428
429

**Note**: glibc >= 2.14 is required.

430
431
**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

432
433
macOS
^^^^^
434

435
On macOS an MPI version of LightGBM can be built using **Open MPI**, **CMake** and **Apple Clang** or **gcc**.
436

437
438
Apple Clang
***********
439

440
Only **Apple Clang** version 8.1 or higher is supported.
441

442
1. Install `CMake`_ :
443

444
   .. code:: sh
445

446
447
448
449
     brew install cmake

2. Install **OpenMP**:

450
   .. code:: sh
451
452
453
454
455

     brew install libomp

3. Install **Open MPI**:

456
   .. code:: sh
457
458
459
460
461

     brew install open-mpi

4. Run the following commands:

462
   .. code:: sh
463

464
465
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
466
467
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
468
469
470
471

gcc
***

472
1. Install `CMake`_ :
473

474
   .. code:: sh
475
476
477
478
479

     brew install cmake

2. Install **gcc**:

480
   .. code:: sh
481
482
483
484
485

     brew install gcc

3. Install **Open MPI**:

486
   .. code:: sh
487
488
489
490
491

     brew install open-mpi

4. Run the following commands:

492
   .. code:: sh
493

494
495
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
496
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
497
498
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
499
500
501
502
503
504
505

Build GPU Version
~~~~~~~~~~~~~~~~~

Linux
^^^^^

506
On Linux a GPU version of LightGBM (``device_type=gpu``) can be built using **OpenCL**, **Boost**, **CMake** and **gcc** or **Clang**.
507

508
509
The following dependencies should be installed before compilation:

510
-  **OpenCL** 1.2 headers and libraries, which is usually provided by GPU manufacture.
511

512
   The generic OpenCL ICD packages (for example, Debian package ``ocl-icd-libopencl1`` and ``ocl-icd-opencl-dev``) can also be used.
513

514
-  **libboost** 1.56 or later (1.61 or later is recommended).
515
516
517
518
519

   We use Boost.Compute as the interface to GPU, which is part of the Boost library since version 1.61. However, since we include the source code of Boost.Compute as a submodule, we only require the host has Boost 1.56 or later installed. We also use Boost.Align for memory allocation. Boost.Compute requires Boost.System and Boost.Filesystem to store offline kernel cache.

   The following Debian packages should provide necessary Boost libraries: ``libboost-dev``, ``libboost-system-dev``, ``libboost-filesystem-dev``.

520
-  **CMake**
521
522
523

To build LightGBM GPU version, run the following commands:

524
.. code:: sh
525

526
527
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
528
  cmake -B build -S . -DUSE_GPU=1
529
  # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
530
531
  # cmake -B build -S . -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/
  cmake --build build
532

533
534
535
536
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

537
538
539
Windows
^^^^^^^

540
On Windows a GPU version of LightGBM (``device_type=gpu``) can be built using **OpenCL**, **Boost**, **CMake** and **VS Build Tools** or **MinGW**.
541

542
If you use **MinGW**, the build procedure is similar to the build on Linux. Refer to `GPU Windows Compilation <./GPU-Windows.rst>`__ to get more details.
543

544
545
Following procedure is for the **MSVC** (Microsoft Visual C++) build.

546
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is installed).
547
548
549
550
551

2. Install **OpenCL** for Windows. The installation depends on the brand (NVIDIA, AMD, Intel) of your GPU card.

   - For running on Intel, get `Intel SDK for OpenCL`_.

552
   - For running on AMD, get AMD APP SDK.
553
554
555

   - For running on NVIDIA, get `CUDA Toolkit`_.

556
557
   Further reading and correspondence table: `GPU SDK Correspondence and Device Targeting Table <./GPU-Targets.rst>`__.

Nikita Titov's avatar
Nikita Titov committed
558
3. Install `Boost Binaries`_.
559

560
   **Note**: Match your Visual C++ version:
561

562
563
   Visual Studio 2015 -> ``msvc-14.0-64.exe``,

564
565
   Visual Studio 2017 -> ``msvc-14.1-64.exe``,

566
567
568
   Visual Studio 2019 -> ``msvc-14.2-64.exe``,

   Visual Studio 2022 -> ``msvc-14.3-64.exe``.
569
570
571

4. Run the following commands:

572
   .. code:: console
573

574
     git clone --recursive https://github.com/microsoft/LightGBM
575
     cd LightGBM
576
     cmake -B build -S . -A x64 -DUSE_GPU=1 -DBOOST_ROOT=C:/local/boost_1_63_0 -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0
577
     # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
578
579
     # cmake -B build -S . -A x64 -DUSE_GPU=1 -DBOOST_ROOT=C:/local/boost_1_63_0 -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0 -DOpenCL_LIBRARY="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/OpenCL.lib" -DOpenCL_INCLUDE_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/include"
     cmake --build build --target ALL_BUILD --config Release
580

581
   **Note**: ``C:/local/boost_1_63_0`` and ``C:/local/boost_1_63_0/lib64-msvc-14.0`` are locations of your **Boost** binaries (assuming you've downloaded 1.63.0 version for Visual Studio 2015).
582
583
584
585

Docker
^^^^^^

586
Refer to `GPU Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker/gpu>`__.
587

588
589
Build CUDA Version
~~~~~~~~~~~~~~~~~~
590

591
The `original GPU build <#build-gpu-version>`__ of LightGBM (``device_type=gpu``) is based on OpenCL.
592

593
594
The CUDA-based build (``device_type=cuda``) is a separate implementation.
Use this version in Linux environments with an NVIDIA GPU with compute capability 6.0 or higher.
595
596
597
598

Linux
^^^^^

599
On Linux a CUDA version of LightGBM can be built using **CUDA**, **CMake** and **gcc** or **Clang**.
600
601
602

The following dependencies should be installed before compilation:

603
-  **CUDA** 11.0 or later libraries. Please refer to `this detailed guide`_. Pay great attention to the minimum required versions of host compilers listed in the table from that guide and use only recommended versions of compilers.
604

605
-  **CMake**
606
607
608

To build LightGBM CUDA version, run the following commands:

609
.. code:: sh
610

611
612
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
613
614
  cmake -B build -S . -DUSE_CUDA=1
  cmake --build build -j4
615

616
617
618
619
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

620
621
622
623
624
625
626
627
628
629
630
macOS
^^^^^

The CUDA version is not supported on macOS.

Windows
^^^^^^^

The CUDA version is not supported on Windows.
Use the GPU version (``device_type=gpu``) for GPU acceleration on Windows.

631
632
633
Build HDFS Version
~~~~~~~~~~~~~~~~~~

634
The HDFS version of LightGBM was tested on CDH-5.14.4 cluster.
635
636
637
638

Linux
^^^^^

639
On Linux a HDFS version of LightGBM can be built using **CMake** and **gcc**.
640

641
1. Install `CMake`_.
fanliwen's avatar
fanliwen committed
642
643
644

2. Run the following commands:

645
   .. code:: sh
fanliwen's avatar
fanliwen committed
646

647
648
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
649
     cmake -B build -S . -DUSE_HDFS=ON
650
651
652
653
654
655
     # if you have installed HDFS to a customized location, you should specify paths to HDFS headers (hdfs.h) and library (libhdfs.so) like the following:
     # cmake \
     #   -DUSE_HDFS=ON \
     #   -DHDFS_LIB="/opt/cloudera/parcels/CDH-5.14.4-1.cdh5.14.4.p0.3/lib64/libhdfs.so" \
     #   -DHDFS_INCLUDE_DIR="/opt/cloudera/parcels/CDH-5.14.4-1.cdh5.14.4.p0.3/include/" \
     #   ..
656
     cmake --build build -j4
fanliwen's avatar
fanliwen committed
657

658
659
660
661
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

662
663
664
Build Java Wrapper
~~~~~~~~~~~~~~~~~~

665
Using the following instructions you can generate a JAR file containing the LightGBM `C API <./Development-Guide.rst#c-api>`__ wrapped by **SWIG**.
666
667
668
669

Windows
^^^^^^^

670
On Windows a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **VS Build Tools** or **MinGW**.
671

672
673
VS Build Tools
**************
674

675
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
676
677
678
679
680

2. Install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).

3. Run the following commands:

681
   .. code:: console
682

683
     git clone --recursive https://github.com/microsoft/LightGBM
684
     cd LightGBM
685
686
     cmake -B build -S . -A x64 -DUSE_SWIG=ON
     cmake --build build --target ALL_BUILD --config Release
687

688
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/Release`` folder.
689
690
691
692
693
694
695
696
697
698

MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).

3. Run the following commands:

699
   .. code:: console
700

701
     git clone --recursive https://github.com/microsoft/LightGBM
702
     cd LightGBM
703
704
     cmake -B build -S . -G "MinGW Makefiles" -DUSE_SWIG=ON
     cmake --build build -j4
705

706
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/`` folder.
707

708
**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles" -DUSE_SWIG=ON`` one more time if you encounter the ``sh.exe was found in your PATH`` error.
709

710
It is recommended to use **VS Build Tools (Visual Studio)** since it has better multithreading efficiency in **Windows** for many-core systems
711
712
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).

713
714
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.

715
716
717
Linux
^^^^^

718
On Linux a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **gcc** or **Clang**.
719

720
1. Install `CMake`_, `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).
721

722
2. Run the following commands:
723

724
   .. code:: sh
725

726
727
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
728
729
     cmake -B build -S . -DUSE_SWIG=ON
     cmake --build build -j4
730

731
732
733
734
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

735
736
737
macOS
^^^^^

738
On macOS a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **Apple Clang** or **gcc**.
739
740
741
742
743
744
745
746
747

First, install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).
Then, either follow the **Apple Clang** or **gcc** installation instructions below.

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

748
1. Install `CMake`_ :
749

750
   .. code:: sh
751
752
753
754
755

     brew install cmake

2. Install **OpenMP**:

756
   .. code:: sh
757
758
759
760
761

     brew install libomp

3. Run the following commands:

762
   .. code:: sh
763

764
765
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
766
767
     cmake -B build -S . -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON
     cmake --build build -j4
768
769
770
771

gcc
***

772
1. Install `CMake`_ :
773

774
   .. code:: sh
775
776
777
778
779

     brew install cmake

2. Install **gcc**:

780
   .. code:: sh
781
782
783
784
785

     brew install gcc

3. Run the following commands:

786
   .. code:: sh
787

788
789
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
790
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
791
792
     cmake -B build -S . -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON
     cmake --build build -j4
793
794
795

Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.

796
797
798
799
800
801
802
803
Build C++ Unit Tests
~~~~~~~~~~~~~~~~~~~~

Windows
^^^^^^^

On Windows, C++ unit tests of LightGBM can be built using **CMake** and **VS Build Tools**.

804
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
805
806
807

2. Run the following commands:

808
   .. code:: console
809
810
811

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
812
813
     cmake -B build -S . -A x64 -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm --config Debug
814
815
816
817
818
819
820
821
822
823
824
825

The ``.exe`` file will be in ``LightGBM/Debug`` folder.

Linux
^^^^^

On Linux a C++ unit tests of LightGBM can be built using **CMake** and **gcc** or **Clang**.

1. Install `CMake`_.

2. Run the following commands:

826
   .. code:: sh
827
828
829

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
830
831
     cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm -j4
832
833
834
835
836
837
838
839
840
841
842
843
844

**Note**: glibc >= 2.14 is required.

macOS
^^^^^

On macOS a C++ unit tests of LightGBM can be built using **CMake** and **Apple Clang** or **gcc**.

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

845
1. Install `CMake`_ :
846

847
   .. code:: sh
848
849
850
851
852

     brew install cmake

2. Run the following commands:

853
   .. code:: sh
854
855
856

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
857
858
     cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm -j4
859
860
861
862

gcc
***

863
1. Install `CMake`_ :
864

865
   .. code:: sh
866
867
868
869
870

     brew install cmake

2. Install **gcc**:

871
   .. code:: sh
872
873
874
875
876

     brew install gcc

3. Run the following commands:

877
   .. code:: sh
878
879
880
881

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
882
883
     cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm -j4
884

885

886
887
888
.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
   :target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html

889
.. _Python-package: https://github.com/microsoft/LightGBM/tree/master/python-package
890

891
.. _R-package: https://github.com/microsoft/LightGBM/tree/master/R-package
892

893
.. _Visual Studio: https://visualstudio.microsoft.com/downloads/
894
895
896
897
898

.. _Git for Windows: https://git-scm.com/download/win

.. _CMake: https://cmake.org/

899
.. _VS Build Tools: https://visualstudio.microsoft.com/downloads/
900

901
.. _MinGW-w64: https://www.mingw-w64.org/downloads/
902
903
904
905
906

.. _MPI: https://en.wikipedia.org/wiki/Message_Passing_Interface

.. _RDMA: https://en.wikipedia.org/wiki/Remote_direct_memory_access

907
.. _MS MPI: https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi-release-notes
908
909
910
911
912
913
914

.. _Open MPI: https://www.open-mpi.org/

.. _Intel SDK for OpenCL: https://software.intel.com/en-us/articles/opencl-drivers

.. _CUDA Toolkit: https://developer.nvidia.com/cuda-downloads

915
.. _Boost Binaries: https://sourceforge.net/projects/boost/files/boost-binaries/
916

James Lamb's avatar
James Lamb committed
917
.. _SWIG: https://www.swig.org/download.html
918
919

.. _this detailed guide: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
920
921

.. _following docs: https://github.com/google/sanitizers/wiki