8

我的问题与Boost 和 OpenCV 库与 Eclipse CDR 的静态链接有关。错误,而我试图做的比这里描述的多一点:如何创建一个可以使用 Boost 和 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 行)。

4

1 回答 1

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)在编译过程中导致错误。这没什么好奇怪的。通常,您永远不应该在包含完成之前放置“使用”行。

于 2011-03-27T13:49:18.683 回答