0

我是 blitz 库的初学者。当我尝试在 Blitz++ 用户指南中编译输入和输出数组的代码时,如下所示:

#include <blitz/array.h>
#include <fstream>

BZ_USING_NAMESPACE(blitz)

const char* filename = "io.data";

void write_arrays()
{
ofstream ofs(filename);
if (ofs.bad())
{
    cerr << "Unable to write to file: " << filename << endl;
    exit(1);
}

Array<float,3> A(3,4,5);
A = 111 + tensor::i + 10 * tensor::j + 100 * tensor::k;
ofs << A << endl;

Array<float,2> B(3,4);
B = 11 + tensor::i + 10 * tensor::j;
ofs << B << endl;

Array<float,1> C(4);
C = 1 + tensor::i;
ofs << C << endl;
}

int main()
{
write_arrays();

ifstream ifs(filename);
if (ifs.bad())
{
    cerr << "Unable to open file: " << filename << endl;
    exit(1);
}

Array<float,3> A;
Array<float,2> B;
Array<float,1> C;

ifs >> A >> B >> C;

cout << "Arrays restored from file: " << A << B << C << endl;

return 0;
}

我总是遇到以下错误:

"
readtest.cpp:(.text+0x246): undefined reference to `blitz::tensor::k'
readtest.cpp:(.text+0x26c): undefined reference to `blitz::tensor::j'
readtest.cpp:(.text+0x281): undefined reference to `blitz::tensor::i'
readtest.cpp:(.text+0x69a): undefined reference to `blitz::tensor::j'
readtest.cpp:(.text+0x6b8): undefined reference to `blitz::tensor::i'
readtest.cpp:(.text+0x981): undefined reference to `blitz::tensor::i'
"

有人可以帮我吗?非常感谢!

4

1 回答 1

0

我遇到了这个问题。不要尝试使用 tensor::i 和 tensor::j,而是声明以下内容:

firstIndex i;
secondIndex j;
thirdIndex k;

然后,您可以直接在代码中使用它们,例如:

A = 111 + i + 10 * j + 100 * k;

我知道他们的文档另有说法,但显然他们没有编译他们的例子。

于 2014-02-21T03:18:41.407 回答