在C ++中链接错误

时间:2017-05-31 09:45:27

标签: gcc makefile compilation xgboost linker-errors

问题here给出了一个如何使用xgboost的例子 - 一个用C ++编写的机器学习库。我想运行该示例,因此安装C ++库。我将/lib个文件添加到/usr/local/lib/src个文件到/usr/local/src

我能够编译这个例子的很多部分:

#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]);

}

但是,我收到了链接错误:

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

我该如何解决这个问题。我断定cpp文件丢失了,但我不知道放在哪里。我想获得有关如何继续安装的帮助。

我也尝试过使用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)

我把Makefile,main.cpp和xgboost目录放在同一个文件夹中。 在这种情况下,我得到一个更长的链接错误。错误太长,无法完全包含。 Here它是。

0 个答案:

没有答案