犰狳& Windows上的代码块

时间:2015-04-17 00:00:32

标签: c++ windows codeblocks linker-errors armadillo

我在使用Armadillo 5.000.1在Windows 8.1上使用CodeBlocks 13.12时遇到很大麻烦。


  • project build options -> linker settings我已添加了库..\armadillo-5.000.1\examples\lib_win64\blas_win64_MT.lib..\armadillo-5.000.1\examples\lib_win64\lapack_win64_MT.lib
  • project build options->search directories我已将..\armadillo-5.000.1\include..\..\..\..\..\Program Files\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev2\mingw64\include添加到编译器,..\armadillo-5.000.1\examples\lib_win64添加到链接器。
  • 我已在#define ARMA_USE_LAPACK中取消评论#define ARMA_USE_BLASconfig.hpp
  • 我(我认为)使用64位mingw编译器。

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

-------------- Build: Debug in CS156b (compiler: GNU GCC Compiler)---------------

g++.exe -L..\armadillo-5.000.1\examples\lib_win64 -o bin\Debug\CS156b.exe obj\Debug\armadillo-5.000.1\examples\example1.o obj\Debug\load_data3.o   ..\armadillo-5.000.1\examples\lib_win64\lapack_win64_MT.lib ..\armadillo-5.000.1\examples\lib_win64\blas_win64_MT.lib
..\armadillo-5.000.1\examples\lib_win64\lapack_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.

有人知道我做错了吗?

2 个答案:

答案 0 :(得分:1)

问题1: 不幸的是,我不知道Codeblocks是什么。但显然链接器不了解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);

答案 1 :(得分:1)

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

相关问题