Boost、OpenCV和Eigen库之间的冲突?

Boost、OpenCV和Eigen库之间的冲突?,boost,opencv,mingw,eclipse-cdt,eigen,Boost,Opencv,Mingw,Eclipse Cdt,Eigen,我的问题与此相关,而我尝试做的比这里描述的更多一些:,即使用Boost的文件系统库遍历目录,并使用OpenCV对图像文件进行一些处理 我使用MinGW编译了文件系统和其他库,并尝试在Windows7 64位系统上使用EclipseCDT运行Boost1.45、OpenCV 2.2和Egene2。如果单独在项目中使用文件系统库,则文件系统库编译和运行不会出现问题,但与上面的其他两个库结合使用时,我会遇到以下错误: In file included from C:\boost_1_45_0/boos

我的问题与此相关,而我尝试做的比这里描述的更多一些:,即使用Boost的文件系统库遍历目录,并使用OpenCV对图像文件进行一些处理

我使用MinGW编译了文件系统和其他库,并尝试在Windows7 64位系统上使用EclipseCDT运行Boost1.45、OpenCV 2.2和Egene2。如果单独在项目中使用文件系统库,则文件系统库编译和运行不会出现问题,但与上面的其他两个库结合使用时,我会遇到以下错误:

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' 
在C:\boost\u 1\u 45\u 0/boost/filesystem/v3/path\u traits.hpp:22:0中包含的文件中,
从C:\boost\u 1\u 45\u 0/boost/filesystem/v3/path.hpp:25,
从C:\boost\u 1\u 45\u 0/boost/filesystem.hpp:32,
from..\src\ComputeNatScaleFunction.cpp:18:
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:在“boost::decay”的实例化中:
C:\cmake_binaries\include/opencv2/core/operations.hpp:766:23:从此处实例化
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:28:66:错误:“cv::”是/使用匿名类型
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:28:66:错误:尝试实例化“模板结构boost::删除\u引用”
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:38:17:错误:“cv:”是/使用匿名类型
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:38:17:错误:尝试实例化“模板结构boost::删除\u引用”
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:在“boost::decay”的实例化中:
C:\cmake_binaries\include/opencv2/core/operations.hpp:917:21:从此处实例化
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:28:66:错误:“cv::”是/使用匿名类型
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:28:66:错误:尝试实例化“模板结构boost::删除\u引用”
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:38:17:错误:“cv:”是/使用匿名类型
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:38:17:错误:尝试实例化“模板结构boost::删除\u引用”
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:在“boost::decay”的实例化中:
C:\Eigen2/Eigen/src/Core/GenericPacketMath.h:116:18:从此处实例化
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:28:66:error:'Eigen::'是/使用匿名类型
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:28:66:错误:尝试实例化“模板结构boost::删除\u引用”
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:38:17:error:'Eigen::'是/使用匿名类型
C:\boost\u 1\u 45\u 0/boost/type\u traits/decay.hpp:38:17:错误:尝试实例化“模板结构boost::删除\u引用”
等等


关于这些库可能相互冲突的原因,有什么提示吗?编译器没有通过文件系统的include(即第18行)。

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

#include <boost/filesystem.hpp>
using namespace boost::filesystem;
#include <Eigen/Core>
#包括
使用名称空间boost::filesystem;
#包括
失败了,但是

#include <boost/filesystem.hpp>
#include <Eigen/Core>
using namespace boost::filesystem;
#包括
#包括
使用名称空间boost::filesystem;
工作


原因是,如果将boost::filesystem添加到全局名称空间,它会污染全局名称空间,并导致一些依赖于未受污染名称空间的代码(这里是:eigen)在编译过程中导致错误。这没什么奇怪的。通常,在include完成之前,您不应该放置“using”行。

您可以使用类似
namespace bfs=boost::filesystem以减少类型负载
;)。这很奇怪,但这确实解决了问题。谢谢根据经验,您应该始终使用
指令在任何
之前包含所有头文件。在您的例子中,您将相当多的符号拉入全局名称空间,这可能会“混淆”Eigen。@Greystache,@vkotor:using“
using namespace boost::filesystem
”将
boost::filesystem
中的所有符号名称转储到全局命名空间中,因此如果
boost::filesystem
有一个名为
Foo
的类,而
Eigen
有一个名为
Foo
的类,它们将发生冲突,编译器将不知道使用哪个。