boost - Boost、OpenCV 和 Eigen 库之间存在冲突?

标签 boost opencv mingw eclipse-cdt eigen

我的问题与 Static linking of Boost and OpenCV libs with Eclipse CDR. errors 有点相关,而我想做的比这里描述的要多一点:How to create a program that can read all the images in folder using Boost and OpenCV? ,即使用 Boost 的文件系统库遍历目录,并使用 OpenCV 对图像文件进行一些处理。

我使用 MinGW 编译文件系统和其他库,并尝试在 Windows 7 64 位系统上使用 Eclipse CDT 运行 Boost 1.45、OpenCV 2.2 和 Eigen2。如果单独在项目中使用文件系统库,编译和运行没有问题,但与上面的其他两个库结合使用,我得到以下错误:

In file included from C:\boost_1_45_0/boost/filesystem/v3/path_traits.hpp:22:0, 
                 from C:\boost_1_45_0/boost/filesystem/v3/path.hpp:25, 
                 from C:\boost_1_45_0/boost/filesystem.hpp:32, 
                 from ..\src\ComputeNatScaleFunction.cpp:18: 
C:\boost_1_45_0/boost/type_traits/decay.hpp: In instantiation of 'boost::decay<cv::<anonymous enum> >': 
C:\cmake_binaries\include/opencv2/core/operations.hpp:766:23:   instantiated from here 
C:\boost_1_45_0/boost/type_traits/decay.hpp:28:66: error: 'cv::' is/uses anonymous type 
C:\boost_1_45_0/boost/type_traits/decay.hpp:28:66: error:   trying to instantiate 'template struct boost::remove_reference' 
C:\boost_1_45_0/boost/type_traits/decay.hpp:38:17: error: 'cv::' is/uses anonymous type 
C:\boost_1_45_0/boost/type_traits/decay.hpp:38:17: error:   trying to instantiate 'template struct boost::remove_reference' 
C:\boost_1_45_0/boost/type_traits/decay.hpp: In instantiation of 'boost::decay<cv::<anonymous enum> >': 
C:\cmake_binaries\include/opencv2/core/operations.hpp:917:21:   instantiated from here 
C:\boost_1_45_0/boost/type_traits/decay.hpp:28:66: error: 'cv::' is/uses anonymous type 
C:\boost_1_45_0/boost/type_traits/decay.hpp:28:66: error:   trying to instantiate 'template struct boost::remove_reference' 
C:\boost_1_45_0/boost/type_traits/decay.hpp:38:17: error: 'cv::' is/uses anonymous type 
C:\boost_1_45_0/boost/type_traits/decay.hpp:38:17: error:   trying to instantiate 'template struct boost::remove_reference' 
C:\boost_1_45_0/boost/type_traits/decay.hpp: In instantiation of 'boost::decay<Eigen::<anonymous enum> >': 
C:\Eigen2/Eigen/src/Core/GenericPacketMath.h:116:18:   instantiated from here 
C:\boost_1_45_0/boost/type_traits/decay.hpp:28:66: error: 'Eigen::' is/uses anonymous type 
C:\boost_1_45_0/boost/type_traits/decay.hpp:28:66: error:   trying to instantiate 'template struct boost::remove_reference' 
C:\boost_1_45_0/boost/type_traits/decay.hpp:38:17: error: 'Eigen::' is/uses anonymous type 
C:\boost_1_45_0/boost/type_traits/decay.hpp:38:17: error:   trying to instantiate 'template struct boost::remove_reference' 

关于为什么这些库可能相互冲突的任何提示?编译器没有通过文件系统的包含(即第 18 行)。

最佳答案

在包含 Eigen 之前使用 boost::filesystem 命名空间会导致编译器失败:

#include <boost/filesystem.hpp>
using namespace boost::filesystem;
#include <Eigen/Core>

失败了,但是

#include <boost/filesystem.hpp>
#include <Eigen/Core>
using namespace boost::filesystem;

有效。

原因是如果将boost::filesystem添加到全局命名空间,会污染它,导致一些依赖未污染命名空间的代码(这里:eigen)在编译时出错。这没什么奇怪的。通常你不应该在你的包含完成之前放置“using”行。

关于boost - Boost、OpenCV 和 Eigen 库之间存在冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5327325/

相关文章:

c++ - boost::asio::deadline_timer 不调用处理程序

c++ - 如何转换不同类型的迭代器

python - 如何关闭轮廓而不是边缘 - OpenCV

c++ - 使用 sublime text 2 错误使用 mingw 编译 SDL2

c++ - Boost.Regex 解析

python - 如何在python中找到拐点?

c++ - for 循环和点的问题

c - 对 CreateProcessWithLogonW 的 undefined reference

c++ - 使用参数从 cmd.exe 执行 MSYS

c++ - 如何从 C FILE* 创建 C++ streambuf 对象,与指向的 FILE 对象共享其缓冲区(和缓冲区状态)?