Installation-Guide.rst 25.7 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
125
**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).

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

128
129
130
131
132
133
134
135
136
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
137
138
     cmake -B build -S . -G 'Ninja'
     cmake --build build -j2
139

140
141
macOS
~~~~~
142

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

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

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

150
151
152
Install Using ``Homebrew``
**************************

153
.. code:: sh
154
155
156
157
158
159

  brew install lightgbm

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

160
1. Install `CMake`_ :
Nikita Titov's avatar
Nikita Titov committed
161

162
   .. code:: sh
Nikita Titov's avatar
Nikita Titov committed
163

164
     brew install cmake
fanliwen's avatar
fanliwen committed
165

166
2. Install **OpenMP**:
fanliwen's avatar
fanliwen committed
167

168
   .. code:: sh
fanliwen's avatar
fanliwen committed
169
170

     brew install libomp
171
172
173

3. Run the following commands:

174
   .. code:: sh
175

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

181
182
gcc
^^^
183

184
1. Install `CMake`_ :
185

186
   .. code:: sh
187

188
     brew install cmake
189

190
2. Install **gcc**:
191

192
   .. code:: sh
193

194
195
196
197
     brew install gcc

3. Run the following commands:

198
   .. code:: sh
199

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

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

208
209
210
Docker
~~~~~~

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

213
214
215
216
Build Threadless Version (not Recommended)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Windows
^^^^^^^

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

- **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).

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

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.

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

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

255
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).
256
257
258

2. Run the following commands:

259
   .. code:: console
260

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

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

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

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

2. Run the following commands:

275
   .. code:: console
276

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

282
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
283

284
**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.
285
286
287
288

Linux
^^^^^

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

1. Install `CMake`_.

2. Run the following commands:

295
   .. code:: sh
296

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

macOS
^^^^^

305
On macOS a version of LightGBM without OpenMP support can be built using **CMake** and **Apple Clang** or **gcc**.
306
307
308
309
310
311

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

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

312
1. Install `CMake`_ :
313

314
   .. code:: sh
315
316
317
318
319

     brew install cmake

2. Run the following commands:

320
   .. code:: sh
321

322
323
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
324
325
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
326
327
328
329

gcc
***

330
1. Install `CMake`_ :
331

332
   .. code:: sh
333
334
335
336
337

     brew install cmake

2. Install **gcc**:

338
   .. code:: sh
339
340
341
342
343

     brew install gcc

3. Run the following commands:

344
   .. code:: sh
345

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

352
353
354
Build MPI Version
~~~~~~~~~~~~~~~~~

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

358
If you need to run a distributed learning application with high performance communication, you can build the LightGBM with MPI support.
359
360
361
362

Windows
^^^^^^^

363
On Windows an MPI version of LightGBM can be built using
364
365
366

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

367
- **MS MPI**, **CMake** and **VS Build Tools**.
368

369
370
371
With GUI
********

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

374
2. Install `Visual Studio`_ (2015 or newer).
375

376
3. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
377
378
379

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

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

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

384
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release_mpi`` folder.
385
386
387
388

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

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

391
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).
392
393
394

3. Run the following commands:

395
   .. code:: console
396

397
     git clone --recursive https://github.com/microsoft/LightGBM
398
     cd LightGBM
399
400
     cmake -B build -S . -A x64 -DUSE_MPI=ON
     cmake --build build --target ALL_BUILD --config Release
401

402
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
403

404
**Note**: Building MPI version by **MinGW** is not supported due to the miss of MPI library in it.
405
406
407
408

Linux
^^^^^

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

411
1. Install `Open MPI`_.
412

413
2. Install `CMake`_.
414

415
416
3. Run the following commands:

417
   .. code:: sh
418

419
420
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
421
422
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
423

424
425
**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).

426
427
macOS
^^^^^
428

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

431
432
Apple Clang
***********
433

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

436
1. Install `CMake`_ :
437

438
   .. code:: sh
439

440
441
442
443
     brew install cmake

2. Install **OpenMP**:

444
   .. code:: sh
445
446
447
448
449

     brew install libomp

3. Install **Open MPI**:

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

     brew install open-mpi

4. Run the following commands:

456
   .. code:: sh
457

458
459
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
460
461
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
462
463
464
465

gcc
***

466
1. Install `CMake`_ :
467

468
   .. code:: sh
469
470
471
472
473

     brew install cmake

2. Install **gcc**:

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

     brew install gcc

3. Install **Open MPI**:

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

     brew install open-mpi

4. Run the following commands:

486
   .. code:: sh
487

488
489
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
490
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
491
492
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
493
494
495
496
497
498
499

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

Linux
^^^^^

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

502
503
The following dependencies should be installed before compilation:

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

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

508
-  **libboost** 1.56 or later (1.61 or later is recommended).
509
510
511
512
513

   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``.

514
-  **CMake**
515
516
517

To build LightGBM GPU version, run the following commands:

518
.. code:: sh
519

520
521
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
522
  cmake -B build -S . -DUSE_GPU=1
523
  # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
524
525
  # 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
526

527
528
**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).

529
530
531
Windows
^^^^^^^

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

534
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.
535

536
537
Following procedure is for the **MSVC** (Microsoft Visual C++) build.

538
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is installed).
539
540
541
542
543

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`_.

544
   - For running on AMD, get AMD APP SDK.
545
546
547

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

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

Nikita Titov's avatar
Nikita Titov committed
550
3. Install `Boost Binaries`_.
551

552
   **Note**: Match your Visual C++ version:
553

554
555
   Visual Studio 2015 -> ``msvc-14.0-64.exe``,

556
557
   Visual Studio 2017 -> ``msvc-14.1-64.exe``,

558
559
560
   Visual Studio 2019 -> ``msvc-14.2-64.exe``,

   Visual Studio 2022 -> ``msvc-14.3-64.exe``.
561
562
563

4. Run the following commands:

564
   .. code:: console
565

566
     git clone --recursive https://github.com/microsoft/LightGBM
567
     cd LightGBM
568
     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
569
     # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
570
571
     # 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
572

573
   **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).
574
575
576
577

Docker
^^^^^^

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

580
581
Build CUDA Version
~~~~~~~~~~~~~~~~~~
582

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

585
586
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.
587
588
589
590

Linux
^^^^^

591
On Linux a CUDA version of LightGBM can be built using **CUDA**, **CMake** and **gcc** or **Clang**.
592
593
594

The following dependencies should be installed before compilation:

595
-  **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.
596

597
-  **CMake**
598
599
600

To build LightGBM CUDA version, run the following commands:

601
.. code:: sh
602

603
604
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
605
606
  cmake -B build -S . -DUSE_CUDA=1
  cmake --build build -j4
607

608
609
**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).

610
611
612
613
614
615
616
617
618
619
620
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.

621
622
623
Build Java Wrapper
~~~~~~~~~~~~~~~~~~

624
Using the following instructions you can generate a JAR file containing the LightGBM `C API <./Development-Guide.rst#c-api>`__ wrapped by **SWIG**.
625
626
627
628

Windows
^^^^^^^

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

631
632
VS Build Tools
**************
633

634
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).
635
636
637
638
639

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

3. Run the following commands:

640
   .. code:: console
641

642
     git clone --recursive https://github.com/microsoft/LightGBM
643
     cd LightGBM
644
645
     cmake -B build -S . -A x64 -DUSE_SWIG=ON
     cmake --build build --target ALL_BUILD --config Release
646

647
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/Release`` folder.
648
649
650
651
652
653
654
655
656
657

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:

658
   .. code:: console
659

660
     git clone --recursive https://github.com/microsoft/LightGBM
661
     cd LightGBM
662
663
     cmake -B build -S . -G "MinGW Makefiles" -DUSE_SWIG=ON
     cmake --build build -j4
664

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

667
**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.
668

669
It is recommended to use **VS Build Tools (Visual Studio)** since it has better multithreading efficiency in **Windows** for many-core systems
670
671
(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>`__).

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

674
675
676
Linux
^^^^^

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

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

681
2. Run the following commands:
682

683
   .. code:: sh
684

685
686
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
687
688
     cmake -B build -S . -DUSE_SWIG=ON
     cmake --build build -j4
689

690
691
**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).

692
693
694
macOS
^^^^^

695
On macOS a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **Apple Clang** or **gcc**.
696
697
698
699
700
701
702
703
704

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.

705
1. Install `CMake`_ :
706

707
   .. code:: sh
708
709
710
711
712

     brew install cmake

2. Install **OpenMP**:

713
   .. code:: sh
714
715
716
717
718

     brew install libomp

3. Run the following commands:

719
   .. code:: sh
720

721
722
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
723
     cmake -B build -S . -DUSE_SWIG=ON
724
     cmake --build build -j4
725
726
727
728

gcc
***

729
1. Install `CMake`_ :
730

731
   .. code:: sh
732
733
734
735
736

     brew install cmake

2. Install **gcc**:

737
   .. code:: sh
738
739
740
741
742

     brew install gcc

3. Run the following commands:

743
   .. code:: sh
744

745
746
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
747
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
748
     cmake -B build -S . -DUSE_SWIG=ON
749
     cmake --build build -j4
750
751
752

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

753
754
755
756
757
758
759
760
Build C++ Unit Tests
~~~~~~~~~~~~~~~~~~~~

Windows
^^^^^^^

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

761
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).
762
763
764

2. Run the following commands:

765
   .. code:: console
766
767
768

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
769
770
     cmake -B build -S . -A x64 -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm --config Debug
771
772
773
774
775
776
777
778
779
780
781
782

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:

783
   .. code:: sh
784
785
786

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
787
788
     cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm -j4
789
790
791
792
793
794
795
796
797
798
799

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.

800
1. Install `CMake`_ :
801

802
   .. code:: sh
803
804
805
806
807

     brew install cmake

2. Run the following commands:

808
   .. code:: sh
809
810
811

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
812
813
     cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm -j4
814
815
816
817

gcc
***

818
1. Install `CMake`_ :
819

820
   .. code:: sh
821
822
823
824
825

     brew install cmake

2. Install **gcc**:

826
   .. code:: sh
827
828
829
830
831

     brew install gcc

3. Run the following commands:

832
   .. code:: sh
833
834
835
836

     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
837
838
     cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF
     cmake --build build --target testlightgbm -j4
839

840

841
842
843
.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
   :target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html

844
.. _Python-package: https://github.com/microsoft/LightGBM/tree/master/python-package
845

846
.. _R-package: https://github.com/microsoft/LightGBM/tree/master/R-package
847

848
.. _Visual Studio: https://visualstudio.microsoft.com/downloads/
849
850
851
852
853

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

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

854
.. _VS Build Tools: https://visualstudio.microsoft.com/downloads/
855

856
.. _MinGW-w64: https://www.mingw-w64.org/downloads/
857
858
859
860
861

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

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

862
.. _MS MPI: https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi-release-notes
863
864
865
866
867
868
869

.. _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

870
.. _Boost Binaries: https://sourceforge.net/projects/boost/files/boost-binaries/
871

James Lamb's avatar
James Lamb committed
872
.. _SWIG: https://www.swig.org/download.html
873
874

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

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