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

时间:2011-03-16 15:10:34

标签: 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行)。

1 个答案:

答案 0 :(得分:9)

在包含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)在编译期间导致错误。它没什么奇怪的。通常情况下,在完成包含之前,不应该使用“使用”行。