boost/smart_ptr 构建错误
Posted
技术标签:
【中文标题】boost/smart_ptr 构建错误【英文标题】:boost/smart_ptr build error 【发布时间】:2016-12-08 09:22:12 【问题描述】:当我尝试构建我的代码时遇到一些错误,该代码非常旧并且包含
“
In file included from /usr/include/boost/shared_array.hpp:17:0,
from /usr/include/boost/smart_ptr.hpp:22,
from ../para/SSParameters.h:19,
from SSShmooTestAnalyzer.cpp:10:
/usr/include/boost/smart_ptr/shared_array.hpp:83:66: error: 'a' has not been declared
template<class Y, class D, class A> shared_array( Y * p, D d, A a ): px( p ), pn( p, d, a )
^
In file included from /usr/include/boost/shared_array.hpp:17:0,
from /usr/include/boost/smart_ptr.hpp:22,
from ../para/SSParameters.h:19,
from SSShmooTestAnalyzer.cpp:10:
/usr/include/boost/smart_ptr/shared_array.hpp:182:64: error: 'a' has not been declared
template<class Y, class D, class A> void reset( Y * p, D d, A a )
^
In file included from /usr/include/boost/shared_array.hpp:17:0,
from /usr/include/boost/smart_ptr.hpp:22,
from ../para/SSParameters.h:19,
from SSShmooTestAnalyzer.cpp:10:
/usr/include/boost/smart_ptr/shared_array.hpp: In constructor 'boost::shared_array<T>::shared_array(Y*, D, int)':
/usr/include/boost/smart_ptr/shared_array.hpp:83:90: error: 'a' was not declared in this scope
template<class Y, class D, class A> shared_array( Y * p, D d, A a ): px( p ), pn( p, d, a )
^
In file included from /usr/include/boost/shared_array.hpp:17:0,
from /usr/include/boost/smart_ptr.hpp:22,
from ../para/SSParameters.h:19,
from SSShmooTestAnalyzer.cpp:10:
/usr/include/boost/smart_ptr/shared_array.hpp: In member function 'void boost::shared_array<T>::reset(Y*, D, int)':
/usr/include/boost/smart_ptr/shared_array.hpp:184:26: error: 'a' was not declared in this scope
this_type( p, d, a ).swap( *this );
^
而且 allocate_shared_array.hpp 中也有一些错误
In file included from /usr/include/boost/smart_ptr/make_shared.hpp:19:0,
from /usr/include/boost/make_shared.hpp:15,
from /usr/include/boost/smart_ptr.hpp:28,
from SSEMAP.h:14,
from SSDomainResult.h:20,
from s-s-resultAnalyzerFactory.h:14,
from s-s-resultAnalyzerFactory.cpp:8:
/usr/include/boost/smart_ptr/allocate_shared_array.hpp: In function 'typename boost::detail::sp_if_array<T>::type boost::allocate_shared_noinit(const int&, std::size_t)':
/usr/include/boost/smart_ptr/allocate_shared_array.hpp:220:52: error: template argument 1 is invalid
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
^
/usr/include/boost/smart_ptr/allocate_shared_array.hpp:220:56: error: invalid type in declaration before '(' token
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
^
/usr/include/boost/smart_ptr/allocate_shared_array.hpp:220:75: error: expression list treated as compound expression in initializer [-fpermissive]
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
^
/usr/include/boost/smart_ptr/allocate_shared_array.hpp: In function 'typename boost::detail::sp_if_size_array<T>::type boost::allocate_shared_noinit(const int&)':
/usr/include/boost/smart_ptr/allocate_shared_array.hpp:239:53: error: template argument 1 is invalid
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
^
/usr/include/boost/smart_ptr/allocate_shared_array.hpp:239:57: error: invalid type in declaration before '(' token
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
^
/usr/include/boost/smart_ptr/allocate_shared_array.hpp:239:72: error: expression list treated as compound expression in initializer [-fpermissive]
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
^
我不明白为什么它会发布错误。
可以在red hat 5中构建成功,并且可以在boost 1.33.1,gcc 4.1.2中构建。
但它不能在 red hat 7 和 boost 1.53.0 , gcc 4.8.2 中构建。
我知道环境与旧有很大不同。但我也想尝试成功地构建它。最好在不更改代码的情况下构建。
SSShmooTestAnalyzer.cpp 没有关于 boost 和 smart_ptr 的代码。它只是包含名为 SSParameters.h 的标头。
很抱歉,我无法向您展示有关我的项目的所有代码。我可以给你看一些关于 boost 和 smart_ptr 的代码。我应该展示更多内容吗?
SSParameters.h:
#include "tml_base.h"
#include "SSPara.h"
#include <boost/smart_ptr.hpp>
#include <assert.h>
#include <string>
#include <vector>
namespace sols
class ITestSetControl;
using sols::ITestSetControl;
using std::vector;
namespace source_sync
class CSSParameters
public:
............
boost::shared_ptr<CSSEdgePara> &getEdgePara()
return mpEdgePara;
boost::shared_ptr<CSSTimingPara> &getTimingPara()
return mpTimingPara;
boost::shared_ptr<Cs-s-resultPara> &getResultPara()
return mpResultPara;
const boost::shared_ptr<Cs-s-resultPara> &getResultPara() const
return mpResultPara;
const boost::shared_ptr<ITestSetControl> &getTestSetControl() const
return mpTestSet;
..........
private:
.........
boost::shared_ptr<Cs-s-resultPara> mpResultPara;
boost::shared_ptr<CSSEdgePara> mpEdgePara;
boost::shared_ptr<CSSTimingPara> mpTimingPara;
boost::shared_ptr<ITestSetControl> mpTestSet;
.......
;
【问题讨论】:
最终错误不太可能出现在 Boost 中。相反,它在您的代码中的可能性更大,您没有向我们展示的代码。 我明白了,但是我应该给你看哪个代码?这些错误是由标头产生的,所以我不知道我应该给你看哪个代码。 如果您查看错误消息,其中一个错误源自SSShmooTestAnalyzer.cpp
,另一个源自s-s-resultAnalyzerFactory.cpp
。查看这些文件或消息中列出的 your 标头可能是个好主意。尝试一一重构任何智能指针的使用,看看错误何时消失。
@Some 程序员老兄,我无法向您展示所有代码。因为实在太多了。并且错误都是由 headers 产生的,就像 "s-s-resultAnalyzerFactory.cpp : 8" 是代码 "#include 该错误看起来像是您在一个包含在 boost 头文件之前的头文件中错过了右大括号/括号/分号。
【讨论】:
以上是关于boost/smart_ptr 构建错误的主要内容,如果未能解决你的问题,请参考以下文章
最新的 boost 版本中的 static_cast_tag() 替代品