【问题标题】:How to link Armadillo with Eclipse如何将犰狳与 Eclipse 连接起来
【发布时间】:2015-05-27 23:06:56
【问题描述】:

我想在 Eclipse 中使用 Armadillo。然而,所有链接犰狳的说明都是为 Visual Studio 提供的。现在我按照Armadillo library 的自述文件中概述的说明进行操作。我在project(right click)->properties->C/C++ Build->Settings->Cross G++ Compiler->Includes->Inlcude paths(-I) 中添加了Armadillo 包含文件夹,然后在project(right click)->properties->C/C++ Build->Settings->Cross G++ Linker->Libraries->Library search path (-L) 中添加了库文件夹(库文件夹包含lapack 和blas .lib 和.dll 文件)。

但是当我在 Eclipse 中编译代码时出现错误

.....armadillo_bits/lapack_wrapper.hpp:37: 未定义对 `dgetrf_' 的引用。

不应该只是在库文件夹中搜索 .lib 文件并在编译期间包含它们吗?对于此事,我将不胜感激。

问候, TM

【问题讨论】:

    标签: eclipse linker armadillo


    【解决方案1】:

    可以将 Armadillo 库链接到 Eclipse 项目,而您即将这样做!它与任何其他库几乎相同。

    在项目的属性中:

    • GCC C++ 编译器 -> 包含:将文件 armadillo(其中声明了命名空间 arma)的路径添加到包含搜索路径(选项 -I)。示例:/home/alpha/soft/armadillo-4.400.1/include

    • GCC C++ 链接器 -> 库:在库搜索路径中添加文件 libarmadillo.so... 的路径(选项 -L) 示例:/home/alpha/soft/armadillo-4.400.1。添加 armadillolapackblasm 作为库(选项 -l)。 m is for math

    以下是 eclipse 生成的对编译器和链接器的调用:

    make all 
    Building file: ../src/armaeclip.cpp
    Invoking: GCC C++ Compiler
    g++ -I/home/alpha/soft/armadillo-4.100.1/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/armaeclip.d" -MT"src/armaeclip.d" -o "src/armaeclip.o" "../src/armaeclip.cpp"
    Finished building: ../src/armaeclip.cpp
    
    
    
    Building target: armaeclip
    Invoking: GCC C++ Linker
    g++ -L/home/alpha/soft/armadillo-4.100.1 -o "armaeclip" ./src/armaeclip.o   -larmadillo -lblas -lm -llapack
    Finished building target: armaeclip
    **** Build Finished ****
    

    当你运行代码时,你可能会得到类似的东西:

    错误:det():需要启用 ATLAS 或 LAPACK 的使用 在抛出 'std::logic_error' 的实例后调用终止 what(): det(): 需要启用 ATLAS 或 LAPACK 放弃(核心转储)

    为避免此问题,请遵循 faq of Armadillo 的建议:取消注释 /home/alpha/soft/armadillo-4.100.1/include/config.hpp 文件中的 #define ARMA_USE_LAPACK 并重建您的项目。

    【讨论】:

    • 您好弗朗西斯,感谢您的建议。但是我没有 lapack、blas、m 或犰狳的 .so 文件。我仅有的库文件格式为 lapack_WIN64_MT.lib 和 blas_WIN64_MT.lib。当我链接 Armadillo 文件夹并将 lapack 和 blas 添加为库时,我收到错误“找不到 lapack 和 blas”所以我假设我缺少 .so 文件但我在哪里可以找到它们?
    • 您可以尝试将 lapack_WIN64_MTblas_WIN64_MT 添加为库而不是 lapackblas 吗?根据naming convention of MinGW,它可能会解决您的问题。
    • 我试过了,但它显示找不到 lapack_WIN64_MT 和找不到 blas_WIN64_MT。我有点放弃并使用本征线性代数库
    • @francis 它仍然可以完美运行!谢谢!您应该在库中添加“仅添加文本“armadillo”、“lapack”、“blas”和“m”(选项 -l)”。很困惑。
    【解决方案2】:

    您还可以创建 GNU Autotools 项目并添加以下行:

    bin_PROGRAMS=armadillo_example
    armadillo_example_SOURCES=armadillo_example.cpp
    armadillo_example_LDADD=-larmadillo
    

    到您的源代码所在的Makefile.am 文件。

    【讨论】:

      【解决方案3】:

      如果您不需要优化的 BLAS 库,您可以使用 Armadillo 附带的 BLAS 和 LAPACK 库。

      1. 项目属性 > C/C++ 构建 > 设置 > GCC C++ 编译器 > 包含 > 包含路径 (-l):C:\armadillo-x.xxx.x\include
      2. 然后在环境变量>系统变量中,修改路径 变量并添加:C:\armadillo-x.xxx.x\examples\lib_win64\
      3. 项目属性 > C/C++ 常规 > 路径和符号 > 库: blas_win64_MTlapack_win64_MT(添加它们很重要 这样,没有路径或.lib/.dll)

      4. 然后在环境变量>系统变量中,修改Path 变量并添加:C:\armadillo-x.xxx.x\examples\lib_win64\

      你在 Eclipse 中的犰狳库很好用。

      我使用过 Eclipse 4.14.0 和 Armadillo 9.850.1。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-08
        • 1970-01-01
        • 2012-04-27
        • 1970-01-01
        相关资源
        最近更新 更多