Reference articles
Using Xgboost in C + +
C + + Project introduces Xgboost dynamic library
problem background
Xgboost Project official did not provide c_api way of compiling and introduction of tutorials, so at first we are directly to the project source code into our project, very troublesome.
At first we imported the source code into the project, the method of invoking the sources, the code write very redundant, and some APIs can not be used for us. So always think of how to directly introduce Xgboost Static library.
Since we are using the Blade Builder, the first step is to use the Xgboost project that makes the blade rule.
Source code compilation
Https://github.com/dmlc/xgboost
Install the Official document download GitHub source code, compile, and then generate the following 3 static files already 3 include folders, we need these things. XGBOOST/LIB/LIBXGBOOST.A xgboost/include/xgboost/rabit/lib/librabit.a xgboost/rabit/include xgboost/dmlc-core/ LIBDMLC.A xgboost/dmlc-core/include
New Blade Project
Create a new folder Sfxgboot, put just 3 static files, stored in the sfxgboost/lib/directory, the Include folder into the sfxgboost/include/directory.
Create a new build file with the following contents:
Cc_library (
name = ' Sfxgboost ',
optimize = [' O2 ', ' std=c++11 ', ' Fopenmp '],
export_incs = [' Include ']
, Deps = [
': Xgboost ', '
: Rabit ', '
:d MLC ',
]
)
cc_library (
name = ' Xgboost
', Prebuilt = True,
)
cc_library (
name = "DMLC",
prebuilt = True,
)
cc_library (
name = "Rabit",
prebuilt = True,
)
The order introduced in the. A file above is required and cannot be changed.
Other projects introduced
Xgboost as a static library project has been created, then how to introduce the development project. Quite simply, add the following code to your project build:
Cc_binary (
name = ' Test ',
optimize = [' O2 ', ' std=c++11 ', ' G '],
extra_linkflags = ['-fopenmp '],
SRCs = [...
],
incs = [...],
deps = [
' #dl ',
' #z ', '
#rt ',
' # Crypto ',
' #ssl ', '
//build_root/sfxgboost:sfxgboost ',
]
Then add the following code in the header file that requires the calling API
#include "xgboost/c_api.h"
You can call C_api.