Boost、OpenCV和Eigen库之间的冲突?
我的问题与此相关,而我尝试做的比这里描述的更多一些:,即使用Boost的文件系统库遍历目录,并使用OpenCV对图像文件进行一些处理 我使用MinGW编译了文件系统和其他库,并尝试在Windows7 64位系统上使用EclipseCDT运行Boost1.45、OpenCV 2.2和Egene2。如果单独在项目中使用文件系统库,则文件系统库编译和运行不会出现问题,但与上面的其他两个库结合使用时,我会遇到以下错误: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
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'
等等
关于这些库可能相互冲突的原因,有什么提示吗?编译器没有通过文件系统的include,即第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行。您可以使用名称空间bfs=boost::filesystem;减少类型负载;。这很奇怪,但这确实解决了问题。谢谢根据经验,在使用任何指令之前,应该始终包含所有头文件。在您的例子中,您将相当多的符号拉入全局名称空间,这可能会混淆Eigen。@Greystache,@vkotor:using using namespace boost::filesystem将boost::filesystem中的所有符号名称转储到全局名称空间中,因此如果boost::filesystem有一个名为Foo的类,而Eigen有一个名为Foo的类,它们将发生冲突,编译器将不知道使用哪个。