我正在编译一个 alglib 示例程序(有一些更改):
#pragma once
# include "Source\RFLearn.h" \\appropriate header for this simple .cpp program.
# include <LinAlg.h>
# include <stdint.h>
# include <chrono> // for in-game frame clock.
int RFLearn::test_function()
{
alglib::real_2d_array a, b, c;
int n = 2000;
int i, j;
double timeneeded, flops;
// Initialize arrays
a.setlength(n, n);
b.setlength(n, n);
c.setlength(n, n);
for (i = 0; i<n; i++)
for (j = 0; j<n; j++)
{
a[i][j] = alglib::randomreal() - 0.5;
b[i][j] = alglib::randomreal() - 0.5;
c[i][j] = 0.0;
}
// Set global threading settings (applied to all ALGLIB functions);
// default is to perform serial computations, unless parallel execution
// is activated. Parallel execution tries to utilize all cores; this
// behavior can be changed with alglib::setnworkers() call.
alglib::setglobalthreading(alglib::parallel);
// Perform matrix-matrix product.
flops = 2 * pow((double)n, (double)3);
auto timer_start = std::chrono::high_resolution_clock::now();
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 1,
0.0,
c, 0, 0);
auto timer_end = std::chrono::high_resolution_clock::now();
auto duration = timer_end - timer_start;
timeneeded = static_cast<double>(duration.count());
// Evaluate performance
printf("Performance is %.1f GFLOPS\n", (double)(1.0E-9*flops / timeneeded));
return 0;
}
我相信 linAlg 已正确链接(以及它的所有依赖项,尤其是 ap.h 和 ap.cpp)(Preferences->C++->AllOptions->Additional Include Directories -> aglib's source directory。更改链接提供了不同的一组链接器错误。AlgLib 是仅标头库,因此我认为不需要编译任何库并将其添加到链接器中。
编译此代码时出现错误:
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: double * __thiscall alglib::real_2d_array::operator[](int)" (??Areal_2d_array@alglib@@QAEPANH@Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall alglib::real_2d_array::~real_2d_array(void)" (??1real_2d_array@alglib@@UAE@XZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: __thiscall alglib::real_2d_array::real_2d_array(void)" (??0real_2d_array@alglib@@QAE@XZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "struct alglib::xparams const & const alglib::parallel" (?parallel@alglib@@3ABUxparams@1@B)
1>RFLearn.obj : error LNK2001: unresolved external symbol "void __cdecl alglib::rmatrixgemm(int,int,int,double,class alglib::real_2d_array const &,int,int,int,class alglib::real_2d_array const &,int,int,int,double,class alglib::real_2d_array const &,int,int,struct alglib::xparams)" (?rmatrixgemm@alglib@@YAXHHHNABVreal_2d_array@1@HHH0HHHN0HHUxparams@1@@Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "double __cdecl alglib::randomreal(void)" (?randomreal@alglib@@YANXZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: void __thiscall alglib::ae_matrix_wrapper::setlength(int,int)" (?setlength@ae_matrix_wrapper@alglib@@QAEXHH@Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "void __cdecl alglib::setglobalthreading(struct alglib::xparams)" (?setglobalthreading@alglib@@YAXUxparams@1@@Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "struct alglib::xparams const & const alglib::xdefault" (?xdefault@alglib@@3ABUxparams@1@B)
我直觉问题出在此处:http ://www.alglib.net/translator/man/manual.cpp.html#gs_configuring
但我无法判断它的正面或反面。下一步是什么?