【问题标题】:Makefile for a c++ code while using Armadillo matrix library使用 Armadillo 矩阵库时的 C++ 代码生成文件
【发布时间】:2014-07-09 17:14:43
【问题描述】:

我已经安装了 Armadillo 线性代数库来在 Linux mint OS 上进行一些矩阵运算。但是,我的坏处是,我无法使用 makefile 编译和执行我的 c++ 代码:

我的makefile如下:

CC=g++
all: file_1.o main.o
    $(CC)  -o EXCUTE_ALL file_1.o main.o

main.o: main.cpp file_1.h
    $(CC) -c main.cpp

file_1.o: file_1.h
    $(CC) -c file_1.cpp

#running    
run : 
    ./EXCUTE_ALL

.PHONY: clean   
clean:
    rm -f *.o
    rm -f EXCUTE_ALL

file_1.cpp 是:

#include <iostream>
#include <stdio.h>
#include "armadillo"
#include "file_1.h"
using namespace std;
using namespace arma;

mat myclass::product(mat my_matrix)
{
    mat product=my_matrix * my_matrix;
    return product;
}

file_1.h 是:

#include <iostream>
#include <stdio.h>
#include "armadillo"

using namespace std;
using namespace arma;

class myclass{
public:
    mat product(mat matrixAA);
};

Main.cpp 是:

#include <iostream>
#include <stdio.h>
#include "armadillo"
#include "file_1.h"
using namespace std;
using namespace arma;

int main() 
{
    myclass matfile;
    mat BB;
    mat AA=randu<mat>(500,500);
    BB=matfile.product(AA);
    return 0;
}

并得到以下错误:

file_1.o: In function `void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
file_1.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)]+0x53): undefined reference to `wrapper_dgemv_'
file_1.o: In function `void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
file_1.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)]+0x61): undefined reference to `wrapper_dgemm_'
collect2: ld returned 1 exit status
make: *** [all] Error 1

但是,这适用于 makefile,使用以下命令:

 `g++ -o obj Main.cpp file_1.cpp -l armadillo`. 

如果我错过了我的 makefile 中的某些内容,任何人都可以帮助我。谢谢。。

【问题讨论】:

  • 您遇到什么错误?
  • 哦,对不起,我现在发布了错误..谢谢

标签: c++ makefile armadillo linux-mint


【解决方案1】:

您的 Makefile 没有告诉链接器将其与 Armadillo 库链接。解决它的一种方法,虽然我不确定它是否是“良好做法”的方法是将 -l armadillo 添加到“all:”行的末尾。它可能无法找到“EXCUTE_ALL”,因为我没有看到任何创建它的东西,而且我看到它在清理后被删除。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多