Windows上的犰狳和代码块

Armadillo & Codeblocks on windows

本文关键字:代码 Windows      更新时间:2023-10-16

我在让犰狳 5.000.1 在 Windows 8.1 上使用 CodeBlocks 13.12 时遇到了很大的麻烦。


  • project build options -> linker settings,我添加了库..armadillo-5.000.1exampleslib_win64blas_win64_MT.lib..armadillo-5.000.1exampleslib_win64lapack_win64_MT.lib
  • project build options->search directories,我向编译器添加了..armadillo-5.000.1include..........Program Filesmingw-w64x86_64-4.9.2-posix-seh-rt_v4-rev2mingw64include..armadillo-5.000.1exampleslib_win64链接器。
  • 我已经取消了#define ARMA_USE_LAPACK的评论,并在config.hpp#define ARMA_USE_BLAS.
  • 我(我认为)使用的是 64 位 mingw 编译器。

当我运行 example1.cpp 文件时,出现以下错误:

-------------- Build: Debug in CS156b (compiler: GNU GCC Compiler)---------------
g++.exe -L..armadillo-5.000.1exampleslib_win64 -o binDebugCS156b.exe objDebugarmadillo-5.000.1examplesexample1.o objDebugload_data3.o   ..armadillo-5.000.1exampleslib_win64lapack_win64_MT.lib ..armadillo-5.000.1exampleslib_win64blas_win64_MT.lib
..armadillo-5.000.1exampleslib_win64lapack_win64_MT.lib: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

另外,我的队友编写的代码在她的(Linux)计算机上运行良好

#include <iostream>
#include <fstream>
#include <ctime>
#define ARMA_64BIT_WORD
#include <armadillo>
/*
 * Read in data from the um.zip file all.dta
 * and store in a sparse vector. There are
 * 458293 reviewers and 17770 reviews.
 */
int main()
{
using namespace std;
clock_t begin = clock();
vector<double> ratings;
arma::umat locations = arma::umat(2, 102416306);
// Open the file
string line;
ifstream myfile("um/all.dta");
int c = 0;
if (myfile.is_open())
{
    while (getline(myfile, line))
    {
        //cout << line << endl;
        if (c % 100 == 0)
            cout << c<< endl;

        int space1 = line.find(" ");
        int space2 = line.find(" ", space1 + 1);
        int space3 = line.find(" ", space2 + 1);
        // Insert into our temporary data vectors
        locations(0, c) = atoi(line.substr(0, space1).c_str());
        locations(1, c) = atoi(line.substr(space1 + 1, space2).c_str());
        ratings.push_back(atoi(line.substr(space3 + 1).c_str()));
        // cout << user << " " << review << " " << rating << endl;
        /*
        boost::split(split_line, line, boost::is_any_of(" "));
        // Convert data to ints
        for (unsigned int i = 0; i < split_line.size(); ++i)
        {
            line_data.push_back(atoi(split_line[i].c_str()));
        }
        */
        c += 1;

    }
}
// Create the sparse matrix
arma::sp_mat m = arma::sp_mat(locations, arma::vec(ratings));
// Serialize the sparse matrix object
//fstream ofs("sparse_matrix_eigen");
//boost::archive::text_oarchive ar(ofs);
// Write data
//ar & m;
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << elapsed_secs << endl;
cout << m;
}

给我错误:

error: SpMat::SpMat(): number of locations is different than number of values
terminate called after throwing an instance of 'std::logic_error'
  what():  SpMat::SpMat(): number of locations is different than number of values
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Process returned 255 (0xFF)   execution time : 5.181 s
Press any key to continue.

有人知道我做错了什么吗?

问题 1:不幸的是,我不知道代码块是什么。但显然链接器不理解 lapack_win64_MT.lib 文件格式。这与犰狳无关。您运行的是 64 位环境吗?您的链接器是否能够读取那些可能是Visual Studio格式的库?我看到你在这里使用 g++,这可能是问题所在。

问题2:您询问固定大小的位置矩阵,但随后循环访问文件的长度。问题可能是文件中的数据行太少,因此无法正确填充sp_mat。

locations = arma::umat(2, 102416306);

应该相当动态地调整大小(例如来自我的大脑,而不是 100&保证工作):

int no_of_lines;
for (no_of_lines = 0; std::getline(f, line); ++no_of_lines);
locations = arma::umat(2, no_of_lines);

作为关于在队友盒子上工作的代码的说明:她可能在没有调试符号和优化的情况下编译,这可能会导致为了速度而忽略运行时大小检查(例如给你std::logic_error的那个)。