如何为使用Eigen(线性代数的C ++模板库)的C ++项目编写makefile? [英] How to write a makefile for a C++ project which uses Eigen, the C++ template library for linear algebra?

查看:249
本文介绍了如何为使用Eigen(线性代数的C ++模板库)的C ++项目编写makefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eigen库,该库可以实现矩阵运算的矢量化.我不知道如何使用Eigen中提供的文件并编写makefile.使用Eigen的源文件包括下面列出的文件,它们甚至不是头文件(它们只是一些文本文件)-

I'm making use of Eigen library which promises vectorization of matrix operations. I don't know how to use the files given in Eigen and write a makefile. The source files which make use of Eigen include files as listed below, these are not even header files (They are just some text files)-

<Eigen/Core>
<Eigen/Dense>
<Eigen/Eigen>

,依此类推.在Eigen的网页上,提到要使用其功能,我不必构建项目,那么如何将这些文件包含在我的makefile中以构建项目.我的示例main.c文件如下所示. 谁能告诉我如何为该文件编写一个makefile文件吗?-

and so on. On Eigen's webpage, it's mentioned that, in order to use its functions I don't have to build the project, then how can I include these files in my makefile to build my project. My example main.c file looks like this. Can anyone show me how to write a makefile makefile for this file -

#include <Eigen/Core>

// import most common Eigen types 
USING_PART_OF_NAMESPACE_EIGEN

int main(int, char *[])
{
  Matrix3f m3;
  m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
  Matrix4f m4 = Matrix4f::Identity();
  Vector4i v4(1, 2, 3, 4);

  std::cout << "m3\n" << m3 << "\nm4:\n"
    << m4 << "\nv4:\n" << v4 << std::endl;
}

帮助!

推荐答案

根据 Eigen的网站,这是仅标头的库.

According to Eigen's website, this is a header-only library.

这意味着没有任何要编译或链接的内容.相反,只要头文件位于标准位置(在* nix/Mac上为/usr/local/include),那么您所要做的就是将该位置添加到预处理器构建步骤中.

This means there is nothing to compile or link it to. Instead, as long as you have the header files in a standard location (/usr/local/include on *nix/Mac), then all you have to do is add that location to your preprocessor build step.

假设您正在运行* nix/Mac,并且已将所有内容安装到默认位置(例如#include <Eigen/Core>引用文件/usr/local/include/Eigen/Core),那么一个超级简单的makefile如下所示:

Assuming that you are running *nix/Mac, and assuming that you have everything installed to the default locations (e.g. #include <Eigen/Core> references the file /usr/local/include/Eigen/Core), then a SUPER simple makefile would look like this:

main: main.cpp
    g++ -I /usr/local/include main.cpp -o main

用英语说:

  • main取决于main.cpp
  • 要制作main,请使用g++
    • 编译main.cpp
    • 输出文件main
    • 在目录/usr/local/include中查找所有未知的标题
    • main depends on main.cpp
    • to make main, use g++ to
      • compile main.cpp,
      • output file main,
      • looking in the directory /usr/local/include for any headers it doesn't know about

      注意:g++行的前面有一个制表符,而不是四个空格.

      NOTE: there is a TAB in front of the g++ line, NOT four spaces.

      希望有帮助.

      这篇关于如何为使用Eigen(线性代数的C ++模板库)的C ++项目编写makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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