如何为 C++ 编写 makefile使用 Eigen 的项目,C++线性代数的模板库?

发布于 2024-09-10 07:35:10 字数 760 浏览 5 评论 0原文

我正在利用 Eigen 库,它承诺矩阵运算的矢量化。我不知道如何使用 Eigen 中给出的文件并编写 makefile。使用 Eigen 的源文件包括下面列出的文件,这些文件甚至不是头文件(它们只是一些文本文件),

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

等等。在 Eigen 的网页上,提到,为了使用它的功能,我不必构建项目,那么如何将这些文件包含在我的 makefile 中来构建我的项目。我的示例 main.c 文件如下所示。 任何人都可以告诉我如何为此文件编写 makefile makefile -

#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;
}

帮助!

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>

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;
}

Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

活泼老夫 2024-09-17 07:35:10

根据 Eigen 网站,这是一个仅包含标头的库。

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

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

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

用英语表示:

  • main 依赖于 main.cpp
  • 来生成 main,使用g++
    • 编译main.cpp
    • 输出文件
    • 在目录 /usr/local/include 中查找它不知道的任何标头

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

希望有所帮助。

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

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.

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

Which says, in English:

  • 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

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

Hope that helps.

风铃鹿 2024-09-17 07:35:10

他们的文档中有此内容。

g++ -I /path/to/eigen2/ my_program.cpp -o my_program 

There is no library to link to. 

看来您只需将模板(标头)文件路径添加到 Makefile 内的包含目录中即可。

They have this in their documentation .

g++ -I /path/to/eigen2/ my_program.cpp -o my_program 

There is no library to link to. 

It seems you just have to add the template(header) file path to your include directories inside your Makefile.

追星践月 2024-09-17 07:35:10

这些实际上是头文件。 Eigen 是一个模板库,遵循常见的模板实践包括所有头文件中的定义和声明,这与将定义和声明保存在单独文件中的非模板实践相反。当减速和定义分开时,您必须将包含定义的源文件构建到库对象文件中以链接到程序中。

表面上,这已经通过首先包含 Eigen 头文件的行为为您完成了。

只要您已将 Eigen 头文件安装到系统包含路径中,它们就会被编译到您的程序中,而无需您进行任何自定义。如果您尚未将它们安装到包含路径中,只需提供 g++ 的完整路径,如下所示...

g++ -I /path/to/eigen2/ source_file -o output_file

Those are in fact header files. Eigen is a template library, and following common template practice includes definition and declaration all in header files, as apposed to non-template practice of keeping definitions and declarations in separate files. When decelerations and definitions are kept separate, you must build the source files containing definitions into library object files to be linked into your program.

This is already ostensibly done for you merely by the act of including the Eigen header files in the first place.

As long as you have installed the Eigen header files into your system include path, they will be compiled into your program without any customization on your part. If you have not installed them into your include path, simply provide the full path to g++ like so...

g++ -I /path/to/eigen2/ source_file -o output_file
欢你一世 2024-09-17 07:35:10

如果您需要一些 fortran 库,这里是我使用的命令

g++ source.cpp -o output -I/../include -L/../lib -L/../lib64 -lcholmod -lmetis -lamd -lcamd -lccolamd -lcolamd -llapack -lgfortran -lblas

我将实际路径替换为 ..

In case you need some fortran library, here is the command I use

g++ source.cpp -o output -I/../include -L/../lib -L/../lib64 -lcholmod -lmetis -lamd -lcamd -lccolamd -lcolamd -llapack -lgfortran -lblas

I replace the actual path with ..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文