【问题标题】:Static Link for Armadillo犰狳的静态链接
【发布时间】:2018-01-28 14:47:42
【问题描述】:

我尝试应用以下步骤将犰狳库静态链接到 Visual Studio 2017 for C++,但无济于事。平台设置为 x64

  1. C/C++ -> 常规 -> 附加包含目录 -> $(SolutionDir)Dependencies\include
  2. 在源文件中写入#include "armadillo"(也尝试过#include )。
  3. 链接器 -> 输入 -> 附加依赖项 -> blas_win64_MT.lib; lapack_win64_MT.lib
  4. 链接器 -> 常规 -> 附加库目录 -> $(SolutionDir)Dependencies\lib_win64

注意:

include 是具有 armadilloarmadillo_bits 的文件夹的名称em> 步骤 1 中的文件夹。

lib_win64 是具有 blas_win64_MT.liblapack_win64_MT 的文件夹的名称.lib 在第 4 步中

.

我在编译的时候遇到如下错误:

c:\........\dependencies\include\armadillo_bits\arma_rng.hpp(444): 错误 C2760:语法错误:意外标记“标识符”,预期为“;”

c:\........\dependencies\include\armadillo_bits\arma_rng.hpp(524): 注意:参见类模板实例化的参考 'arma::arma_rng::randn<std::complex<_Other>>' 正在编译中

.

arma_rng.hpp 的代码,直接来自犰狳库代码。

template<typename T>
struct arma_rng::randn < std::complex<T> > 
  {
  inline
  operator std::complex<T> () const
    {
    T a, b; //************line 444***************

    arma_rng::randn<T>::dual_val(a, b);

    return std::complex<T>(a, b);
    }


  inline
  static
  void
  fill(std::complex<T>* mem, const uword N)
    {
    ...

  }; //************line 524***************

.

这是直接来自犰狳示例的代码,用于测试我是否正确链接犰狳,目前没有实现头文件:

#include <iostream>
#include <armadillo>

using namespace std;
using namespace arma;

// Armadillo documentation is available at:
// http://arma.sourceforge.net/docs.html

int
main(int argc, char** argv)
  {
  cout << "Armadillo version: " << arma_version::as_string() << endl;

  mat A(2,3);  // directly specify the matrix size (elements are uninitialised)

  cout << "A.n_rows: " << A.n_rows << endl;  // .n_rows and .n_cols are read only
  cout << "A.n_cols: " << A.n_cols << endl;

  A(1,2) = 456.0;  // directly access an element (indexing starts at 0)
  A.print("A:");

  A = 5.0;         // scalars are treated as a 1x1 matrix
  A.print("A:");

  A.set_size(4,5); // change the size (data is not preserved)

  A.fill(5.0);     // set all elements to a particular value
  A.print("A:");

  // endr indicates "end of row"
  A << 0.165300 << 0.454037 << 0.995795 << 0.124098 << 0.047084 << endr
    << 0.688782 << 0.036549 << 0.552848 << 0.937664 << 0.866401 << endr
    << 0.348740 << 0.479388 << 0.506228 << 0.145673 << 0.491547 << endr
    << 0.148678 << 0.682258 << 0.571154 << 0.874724 << 0.444632 << endr
    << 0.245726 << 0.595218 << 0.409327 << 0.367827 << 0.385736 << endr;

  A.print("A:");

  // determinant
  cout << "det(A): " << det(A) << endl;

  // inverse
  cout << "inv(A): " << endl << inv(A) << endl;

  // save matrix as a text file
  A.save("A.txt", raw_ascii);

  // load from file
  mat B;
  B.load("A.txt");

  // submatrices
  cout << "B( span(0,2), span(3,4) ):" << endl << B( span(0,2), span(3,4) ) << endl;

  cout << "B( 0,3, size(3,2) ):" << endl << B( 0,3, size(3,2) ) << endl;

  cout << "B.row(0): " << endl << B.row(0) << endl;

  cout << "B.col(1): " << endl << B.col(1) << endl;

  // transpose
  cout << "B.t(): " << endl << B.t() << endl;

  // maximum from each column (traverse along rows)
  cout << "max(B): " << endl << max(B) << endl;

  // maximum from each row (traverse along columns)
  cout << "max(B,1): " << endl << max(B,1) << endl;

  // maximum value in B
  cout << "max(max(B)) = " << max(max(B)) << endl;

  // sum of each column (traverse along rows)
  cout << "sum(B): " << endl << sum(B) << endl;

  // sum of each row (traverse along columns)
  cout << "sum(B,1) =" << endl << sum(B,1) << endl;

  // sum of all elements
  cout << "accu(B): " << accu(B) << endl;

  // trace = sum along diagonal
  cout << "trace(B): " << trace(B) << endl;

  // generate the identity matrix
  mat C = eye<mat>(4,4);

  // random matrix with values uniformly distributed in the [0,1] interval
  mat D = randu<mat>(4,4);
  D.print("D:");

  // row vectors are treated like a matrix with one row
  rowvec r;
  r << 0.59119 << 0.77321 << 0.60275 << 0.35887 << 0.51683;
  r.print("r:");

  // column vectors are treated like a matrix with one column
  vec q;
  q << 0.14333 << 0.59478 << 0.14481 << 0.58558 << 0.60809;
  q.print("q:");

  // convert matrix to vector; data in matrices is stored column-by-column
  vec v = vectorise(A);
  v.print("v:");

  // dot or inner product
  cout << "as_scalar(r*q): " << as_scalar(r*q) << endl;

  // outer product
  cout << "q*r: " << endl << q*r << endl;

  // multiply-and-accumulate operation (no temporary matrices are created)
  cout << "accu(A % B) = " << accu(A % B) << endl;

  // example of a compound operation
  B += 2.0 * A.t();
  B.print("B:");

  // imat specifies an integer matrix
  imat AA;
  imat BB;

  AA << 1 << 2 << 3 << endr << 4 << 5 << 6 << endr << 7 << 8 << 9;
  BB << 3 << 2 << 1 << endr << 6 << 5 << 4 << endr << 9 << 8 << 7;

  // comparison of matrices (element-wise); output of a relational operator is a umat
  umat ZZ = (AA >= BB);
  ZZ.print("ZZ:");

  // cubes ("3D matrices")
  cube Q( B.n_rows, B.n_cols, 2 );

  Q.slice(0) = B;
  Q.slice(1) = 2.0 * B;

  Q.print("Q:");

  // 2D field of matrices; 3D fields are also supported
  field<mat> F(4,3); 

  for(uword col=0; col < F.n_cols; ++col)
  for(uword row=0; row < F.n_rows; ++row)
    {
    F(row,col) = randu<mat>(2,3);  // each element in field<mat> is a matrix
    }

  F.print("F:");

  return 0;
  }

.

【问题讨论】:

  • 这些错误与链接无关。它们发生在代码解析期间,早在链接完成之前。是否缺少宏定义,或者您是否错误地使用了头文件中声明的符号?请尝试创建一个Minimal, Complete, and Verifiable Example,您可以向我们展示,它会更容易为您提供帮助。
  • 在帖子中的错误周围包含头文件中的几行,比如说每行上方和下方大约 5 行。
  • 我添加了来自犰狳的代码,但我在编译时遇到了问题。 @Someprogrammerdude
  • 没有使用头文件,因为这是犰狳的例子,我已经包含了犰狳@RichardCritten 的一些代码

标签: c++ static-libraries armadillo


【解决方案1】:

请将您的 VS2017 平台工具集更改为 v140 而不是 v141。然后编译,它必须工作。

【讨论】:

    【解决方案2】:

    对于面临同样问题的其他人,使用 VC++ 2015.3 v140 toolset 可以帮助我将 OpenBLASarmadillo 编译为静态库。

    这些是 Visual Studio 2017 (VS2017) 所需的步骤:

    • 如果需要,安装 v140 工具集:
      • 修改VS2017安装(即详细信息here
      • 选中桌面开发C++
      • 在右侧,在 Summary 下单击 Desktop development with C++
      • 在列表底部检查 VC++ 2015.3 v140 桌面工具集(x86、x64)
    • 接下来,您需要告诉编译器使用v140 而不是v141,因此:
      • VS2017中右键项目名称
      • 转到配置属性常规平台工具集
      • 选择Visual Studio 2015 (v140)

    现在您应该可以#include &lt;armadillo&gt; 并编译您的代码了。

    注意事项:

    • 您仍然需要确保设置正确的包含路径(即,如果您通过 Nuget 包管理器安装 armadillo,则只需按照上述步骤操作即可)李>

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      似乎是Visual Studio 2017引起的BUG,与Conformance Mode相关,最近在Visual Studio。他们试图修复它(详情here)。

      VS2017(V141,而不是安装 V140)中的解决方法是禁用一致性模式。您可以尝试这样方式:

      • 项目属性 -> C/C++ -> 语言 -> 一致性模式 -> 禁用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-18
        相关资源
        最近更新 更多