Introduction of Xgboost Static Library in C + + project

Source: Internet
Author: User
Tags xgboost


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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.