包括Eigen

时间:2018-04-30 19:54:44

标签: c++ eigen scientific-computing eigen3

我刚开始使用Eigen而且我遇到了多重定义问题。我已经找到了确切的问题,这是一个很小的例子。

使用:

// File common1.hpp
#include <Eigen/Dense>
// File common2.hpp
#include "common1.hpp"
// File main.cpp
#include "common2.hpp"

clang++ main.cpp编译。

不能工作:

// File common1.hpp
#include <Eigen/Dense>
// File common2.hpp
#include "common1.hpp"
// File common2.cpp
#include "common2.hpp"
// File main.cpp
#include "common2.hpp"

clang++ main.cpp common2.cpp因错误而失败:

/tmp/common2-f75caf.o: In function `bool Eigen::numext::equal_strict<double, double>(double const&, double const&)':
common2.cpp:(.text+0x30): multiple definition of `bool Eigen::numext::equal_strict<double, double>(double const&, double const&)'
/tmp/main-8e7100.o:main.cpp:(.text+0x30): first defined here
/tmp/common2-f75caf.o: In function `bool Eigen::numext::equal_strict<float, float>(float const&, float const&)':
common2.cpp:(.text+0x0): multiple definition of `bool Eigen::numext::equal_strict<float, float>(float const&, float const&)'
/tmp/main-8e7100.o:main.cpp:(.text+0x0): first defined here
/tmp/common2-f75caf.o: In function `bool Eigen::numext::not_equal_strict<double, double>(double const&, double const&)':
common2.cpp:(.text+0x90): multiple definition of `bool Eigen::numext::not_equal_strict<double, double>(double const&, double const&)'
/tmp/main-8e7100.o:main.cpp:(.text+0x90): first defined here
/tmp/common2-f75caf.o: In function `bool Eigen::numext::not_equal_strict<float, float>(float const&, float const&)':
common2.cpp:(.text+0x60): multiple definition of `bool Eigen::numext::not_equal_strict<float, float>(float const&, float const&)'
/tmp/main-8e7100.o:main.cpp:(.text+0x60): first defined here
clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation)

我非常喜欢Eigen的C ++ API,我真的很想继续使用它。我查看了一些使用Eigen的项目,他们使用自己的命名空间执行第二个代码块。我试过了,但得到了同样的错误。任何帮助将不胜感激。

编辑: Clang版本7。 Eigen:在过去一个月左右从Github镜子拉出来。

1 个答案:

答案 0 :(得分:2)

这是https://github.com/eigenteam/eigen-git-mirror/commit/11a3c93ee327dd2be34bc56bc04a5ebcb3340256的结果,其中错误中的相关功能尚未内联。

这一般可以通过使用Eigen的最新版本(编写本文时为3.3.4)来解决,或者更具体地说,通过使用https://github.com/eigenteam/eigen-git-mirror/commit/37ca6e8ee578bf490b04f4e977c4ecb081d35e9f之后或之后的代码来解决

在Bitbucket上,37ca6e是https://bitbucket.org/eigen/eigen/commits/1f08827edccbe08648146cc584fcbd7f4bfb3e33

这两个测试用例现在都有效,感谢所有帮助找到/解决此问题的人。