Windows上的犰狳和代码块
Armadillo & Codeblocks on windows
我在让犰狳 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
的那个)。
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux for Windows上编译C++代码时出错
- 在 Linux 群集上运行 Windows C++代码
- 如何分析在 Windows 上运行C++代码?
- g++ 9.2.1 (Linux) 会导致 seg 错误,但 Windows 上的代码块不会
- 如何在 vim (windows) 中编译和运行 c++ 代码
- Windows Toast 通知不适用于 MS CPP 示例代码
- 如何在Visual Studio 2017中编译Windows XP的代码
- 如何在 Windows API 中检测带有虚拟代码的非字母?
- C++代码在 Linux 上按预期工作,但在 Windows 上则不然
- 为什么我的C 代码在Linux上运行,而在Windows上不运行,是否有RAM内存的问题
- 如何在librdkafka中使用KAFKA的生产者API,并在Windows上使用C ++代码
- 我在Windows和Linux中得到了不同的结果!C++代码
- 有什么方法可以用本机C 代码替换Windows API计时器(settimer)
- 如何使用Visual Studio检测和获取Windows服务的代码覆盖率?
- Windows 控制台代码页 866
- cv:内存位置的异常 - 运行 openCV 代码 Visual Studio 2013 & Visual Studio 2017 - Windows 7
- 如何使用选择正确检测我是在Windows还是Linux中构建C 代码
- Visual Studio代码找不到g++.exe(Windows 10)
- 在c++中嵌入python代码(Windows + minGW + python 2.7.2 + Eclipse)