交叉编译Armadillo线性代数库 [英] Cross-Compiling Armadillo Linear Algebra Library

查看:308
本文介绍了交叉编译Armadillo线性代数库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用 Armadillo线性代数库.当将八度.m文件移植到C ++时,它变得非常好,尤其是当您必须使用本征方法时.

I enjoy using the Armadillo Linear Algebra Library. It becomes extremely nice when porting octave .m files over to C++, especially when you have to use the eigen methods.

但是,当我不得不从我的原始香草G ++中提取程序并将其转储到我的ARM处理器时,我遇到了问题.由于我花了几个小时来弄乱自己的方式,所以我想分享一下,以便其他人可以避免一些挫败感.

However I ran into issues when I had to take my program from my native vanilla G++ and dump it onto my ARM processor. Since I spent a few hours muddling my way though it I wanted to share so others might avoid some frustration.

如果其他人可以添加其他内容,我会喜欢的.这是我用来解决此问题的过程,肯定不是唯一或最佳的方法.

If anyone else could add anything else I would love it. This was the process I used to tackle this and surely isn't the only or best approach.

推荐答案

首先,我使用

First off I use Code Sourcery as my cross-compiler. I know there others out there, but I haven't gotten around to rebuilding for another compiler yet, regardless this should be applicable to any compiler.

Armadillo库需要LAPACK和BLAS,但是Code Sourcery没有Fortran编译器.这使我找到了FAP的LAPACK和BLAS版本.

The Armadillo library requires LAPACK and BLAS, but Code Sourcery has no Fortran compiler. This led me to a f2c'ed version of LAPACK and BLAS.

首先要获取源代码.

  • Armadillo
  • LAPACK & BLAS

一旦有了源,下一步要做的就是交叉编译它们以用于最终硬件.就我而言,是一个使用CodeSourcery的ARM7.在此处阅读自述文件是 REALLY 的好主意,您只需花一些时间阅读它们就可以真正完成所有这些工作.

Once we've got the sources the next thing to do is cross-compile them for our end hardware. In my case an ARM7 using CodeSourcery. Its a REALLY good idea to read the READMEs here, you really can do all of this by just taking the time and reading them.

  1. 首先要做的是更改make.inc文件以查看我们的交叉编译器,而不是普通的GCC.通常,您可以使用$ export,但是我发现通过修改makefile可以更轻松地进行跟踪.

  1. First thing to do is change the make.inc file to look at our cross-compiler instead of the normal GCC. Normally you would $export, but I found it easier to keep track by modifying the makefiles.

从以下位置编辑clapack-3.2.1-CMAKE/make.inc:

Edit clapack-3.2.1-CMAKE/make.inc from:

CC = GCC
LOADER = GCC

收件人:

CC = [CROSS-COMPILER-GCC location]
LOADER = [CROSS-COMPILER-GCC location]

从以下位置编辑clapack-3.2.1-CMAKE/F2CLIBS/libf2c/Makefile:

Edit clapack-3.2.1-CMAKE/F2CLIBS/libf2c/Makefile from:

ld -r -x -o $*.xxx $*.o

收件人:

[CROSS-COMPILER-LD location] -r -x -o $*.xxx $*.o

  • 编译f2c库:

  • Compile the f2c libraries:

    $make f2clib
    

    当我制作f2c库时,我最终会收到一个错误:

    When I make the f2c libraries I get an error at the very end:

    ./a.out > arith.h
    /bin/sh: ./a.out: cannot execute binary file
    make[1]: *** [arith.h] Error 126
    make[1]: Leaving directory `/home/matt/clapack-3.2.1-CMAKE/F2CLIBS/libf2c'
    make: *** [f2clib] Error 2
    

    这里没有实际问题.当然,它会执行困难,它是交叉编译的!

    No actual problem here. Of course it will have trouble executing, it was cross-compiled!

    编译BLAS:

    $make blaslib
    

    完成此操作后,您会发现您有一个新的"blas_XXXXX.a".这是您交叉编译的BLAS库.

    Once this is done you will notice you have a new "blas_XXXXX.a". This is your cross-compiled BLAS library.

    编译LAPACK:

    make.inc将指示您使用$make lapacklib,但这将导致它尝试更多执行交叉编译的项目.而是$cd进入SRC目录,然后:

    The make.inc will point you to use $make lapacklib, but this will lead it to attempt more execution of cross-compiled items. Instead $cd into the SRC directory and:

    $make
    

    应该会生成新的"lapack_XXXXX.a".现在我们有了F2C,LAPACK和BLAS,我建议将它们放置在有意义的位置,以便稍后找到它们.就我而言,我将它们放在我的Code Sourcery编译器/CodeSourcery/arm-none-linux-gnueabi/usr/lib的位置.记住要重命名这些文件:

    That should generate your new "lapack_XXXXX.a". Now that we have our F2C, LAPACK and BLAS I recommend placing them somewhere that makes sense so you can find them later. In my case I placed them where I keep my Code Sourcery compiler /CodeSourcery/arm-none-linux-gnueabi/usr/lib. Remember to rename these files:

    $cp libf2c.a [CROSS-COMPILE LIBRARY PATH]/libf2c.a
    $cp blas_XXXXX.a [CROSS-COMPILE LIBRARY PATH]/libblas.a
    $cp lapack_XXXXX.a [CROSS-COMPILE LIBRARY PATH]/liblapack.a
    

    请记住,它们必须具有"lib",以便以后识别.再次继续,将它们存储在交叉编译的库中.我使用工具链对其进行了设置,以使其更容易与普通的gcc/g ++分开.

    Remember they have to have the "lib" to be recognized later. Again go ahead and store these in your cross-compiled library location. I have it setup with my tool-chain to make it easier to separate from normal gcc/g++.

    3.交叉编译ARMADILLO

    首先阅读自述文件,始终是最好的起点.
    继续运行:

    3. Cross-Compile ARMADILLO

    First off read the README, always the best place to start.
    Go ahead and run:

        $cmake .
    

    这将使一切准备就绪,并生成cmake创建共享的犰狳库所需的一切.我在这里进行操作的方式不是我认为的那样,但是由于我一般都不是makefile的向导,因此我认为展示如何使它交叉编译将很有帮助. 我用以下命令修改了生成的CMakeCache.txt行:

    This will get everything ready and generate everything cmake will need for creating our shared armadillo library. The way I proceeded here is not how I think you are supposed to, but as I am no wizard with makefiles in general I thought it would be helpful to show what I did to get it to cross-compile. I modified the generated CMakeCache.txt lines with the following:

        //CXX compiler.
        CMAKE_CXX_COMPILER:FILEPATH=[CROSS-COMPILER-G++ location]
    

    我知道该CMakeCache.txt文件中的某处可以指定BLAS和LAPACK位置的路径,但是我很难弄清楚.我没有修改这个问题,而是修改了"CMakeFiles/armadillo.dir/link.txt"并手动添加了"-L [交叉编译的BLAS/LAPACK目录].更熟悉此操作的人可以在评论? 接下来,由于我们想在以后编译程序时手动链接BLAS和LAPACK库(如README所述),请修改"include/armadillo_bits/config.hpp",并确保注释掉了使用arma包装器的行:

    I know there is somewhere in that CMakeCache.txt file where you can specify the path to the location of our BLAS and LAPACK, but I struggled to figure it out. Instead of bashing my head against this issue I just modified the "CMakeFiles/armadillo.dir/link.txt" and manually added "-L [Cross-Compiled BLAS/LAPACK directory]. Someone more familiar with how to do this could specify in the comments? Next since we want to manually link the BLAS and LAPACK libraries when we compile our program later (like the README says) modify "include/armadillo_bits/config.hpp" and make sure the line defining the use of the arma wrapper is commented out:

        //  #define ARMA_USE_WRAPPER
    

    剩下要做的就是$cd回到armadillo目录的根目录和

    The only thing left to do is $cd back to the root of the armadillo directory and

        $make
    

    一旦制作完成,您应该可以在程序中使用Armadillo.

    Once the make completes you should be able to use Armadillo in your programs.

    要在程序中使用Armadillo,请添加包含#include <armadillo>和名称空间using namespace arma;.现在,您应该可以使用自己喜欢的所有vecmat了. 通常,使用arma时,在编译时所需要做的就是链接libarmadillo.so库,但是正如我之前所说,我们将需要直接链接BLAS和LAPACK.这是我的GCC C ++编译器synatx:

    To use Armadillo in your program add the include #include <armadillo> and the namespace using namespace arma;. Now you should be able to use all of the vec and mat you feel like. Normally when using arma all you need to do at compile time is to link libarmadillo.so library, but as I stated earlier we will need to link BLAS and LAPACK directly instead. So here is my GCC C++ Compiler synatx:

        [CROSS-COMPILER-G++] -I [CROSS-COMPILED ARMADILLO DIRECTORY]/include ...
    

    和我的链接器:

        [CROSS-COMPILER-G++] -L [CROSS-COMPILED LIBRARY] -o ... -llapack -lf2c -lblas
    

    还请注意,链接库的顺序很重要!首先必须是lapack,然后是f2c,然后是blas.

    Also note that the order in which you link libraries does matter! lapack must come first, then f2c, then blas.

    您真正需要确保发生的一切是,在编译时包括了交叉编译的armadillo目录,并且如上所述正确设置了链接.

    Really all you need to make sure happens is that the cross-compiled armadillo directory is included when you compile and your linking is setup correctly as above.

    再次获得更多信息更好,请随时添加更多评论.对您有用的是不同于我所做的,我做错的,可以做的改进的事情.

    Again more information is better, please feel free to add more comments. What worked for you different that what I did, what I did wrong, what could be done to improve.

    谢谢.

    这篇关于交叉编译Armadillo线性代数库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆