1

The question here gives an example of how to use xgboost - a machine learning library written in C++. I want to run the example, and therefore install the library for C++. I added the /lib files to /usr/local/lib and /src files to /usr/local/src

I am able to compile this much part of the example :

#include <iostream>
#include <xgboost/c_api.h>
using namespace std;
int main(){
    int cols=3,rows=5;
    float train[rows][cols];
    for (int i=0;i<rows;i++)
        for (int j=0;j<cols;j++)
            train[i][j] = (i+1) * (j+1);

    float train_labels[rows];
    for (int i=0;i<rows;i++)
        train_labels[i] = 1+i*i*i;
    DMatrixHandle h_train[1];
    XGDMatrixCreateFromMat((float *) train, rows, cols, -1, &h_train[0]);

}

However, I am getting a linking error:

/tmp/ccuBacNh.o: In function `main':
TerrainPredict.cpp:(.text+0x278): undefined reference to `XGDMatrixCreateFromMat'
collect2: error: ld returned 1 exit status

How can I resolve this. I concluded that cpp files are missing, but I don't know where to put them. I want help regarding how to proceed with installation.

I also tried using a makefile:

LDLIBSOPTIONS=xgboost/lib/libxgboost.a xgboost/rabit/lib/librabit.a xgboost/dmlc-core/libdmlc.a -lpthread
CFLAGS=-I xgboost/include -I xgboost/rabit/include -I  dmlc-core/include
all:
    g++ main.cpp $(CFLAGS) $(LDLIBSOPTIONS)

I put Makefile, main.cpp and xgboost directory in the same folder. In that case I am getting a longer linking error. Error is too long to include fully. Here it is.

Meet Taraviya
  • 869
  • 1
  • 8
  • 27

0 Answers0