如何通过KIT编译收缩层次结构?

时间:2013-07-16 08:01:09

标签: c++ gcc compiler-errors g++ compiler-warnings

我正在尝试用KIT编译Contraction Hierarchies Implementation

该软件已于2009年发布,显然从那时起一直没有得到维护。由于一些事情在平均时间内发生了变化(使用新的C ++标准和编译器版本),代码不再编译现成。

当谈到编译指令时,README并不是非常详细,并且说你应该只调用make。但是,使用make会出现以下错误:

g++  -Wall -W -Wno-unused-parameter  -O6   -c -o main.o main.cpp
In file included from /usr/include/c++/4.8/ext/hash_map:60:0,
                 from command/../io/../datastr/graph/../../io/serialize.h:26,
                 from command/../io/../datastr/graph/edge.h:26,
                 from command/../io/../datastr/graph/graph.h:59,
                 from command/../io/createGraph.h:28,
                 from command/NodeOrder.h:29,
                 from main.cpp:35:
/usr/include/c++/4.8/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
 #warning \
  ^
command/../processing/../EliminationWeight.h:42:35: error: a call to a constructor cannot appear in a constant-expression
     static const Type MAX_VALUE = __DBL_MAX__;
                                   ^
command/../processing/../EliminationWeight.h:43:36: error: a call to a constructor cannot appear in a constant-expression
     static const Type MIN_VALUE = -__DBL_MAX__;
                                    ^
make: *** [main.o] Error 1

我需要做些什么才能进行编译?

1 个答案:

答案 0 :(得分:6)

要使软件编译没有错误,需要执行几个步骤。我用gcc 4.8.1和Boost 1.53.0测试了这些指令。

对构造函数的调用不能出现在常量表达式

(我已经详细回答了这个子问题there,但会重复这里的重要步骤。)

我们遇到的第一个编译错误是由于软件使用GCC编译器的非标准扩展。似乎在软件开发时,这些不必由编译器开关启用,但现代GCC需要这样做。但是,为了将来的兼容性,我们将摆脱它们并以符合标准的方式实现这些功能。

编译器告诉我们问题出在EliminationWeight.h的第42和43行。这些是该文件中的行:

static const Type MAX_VALUE = __DBL_MAX__;
static const Type MIN_VALUE = -__DBL_MAX__;

GCC在这里抱怨,因为标准不涵盖类体中双打的初始化。相反,我们应该分开做。因此,删除初始化并将行更改为以下内容:

static const Type MAX_VALUE;
static const Type MIN_VALUE;

同时删除#include <limits>,因为我们不再需要此文件。

由于我们仍想初始化这些值,因此我们会查看main.cpp并找到第84行及其后的内容:

// doesn't look nice, but required by the compiler (gcc 4)
const EdgeWeight Weight::MAX_VALUE;
const EliminationWeight::Type EliminationWeight::MAX_VALUE;
const EliminationWeight::Type EliminationWeight::MIN_VALUE;

这看起来是进行初始化的最佳位置。更改第86行和第87行以包含以下代码:

const EliminationWeight::Type EliminationWeight::MAX_VALUE = std::numeric_limits< EliminationWeight::Type >::max();
const EliminationWeight::Type EliminationWeight::MIN_VALUE = -std::numeric_limits< EliminationWeight::Type >::max();

同时添加

#include <limits>

main.cpp,因为我们现在正在使用该标头中的std::numeric_limits类。

collect2:错误:ld返回1退出状态

编译现在可以正常工作,但链接将失败,并显示大量错误消息。 (我已经解决了这个问题there,但会在这里重复它的主旨。)

所有错误都与Boost :: Regex的链接有关。这是我机器上的完整错误消息:

g++ -lboost_regex -lboost_iostreams -o main main.o 
main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::unwind_extra_block(bool)':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb]+0x2c): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.o: In function `void boost::re_detail::raise_error > > >(boost::regex_traits_wrapper > > const&, boost::regex_constants::error_type)':
main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0x7d): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xb1): undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xcb): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
main.o: In function `__gnu_cxx::__normal_iterator boost::re_detail::re_is_set_member, char, boost::regex_traits >, unsigned int>(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, boost::re_detail::re_set_long const*, boost::re_detail::regex_data > > const&, bool)':
main.cpp:(.text._ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x17b): undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const'
main.cpp:(.text._ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x4c0): undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform(char const*, char const*) const'
main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::extend_stack()':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv]+0x18): undefined reference to `boost::re_detail::get_mem_block()'
main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::match_imp()':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0xc): undefined reference to `boost::re_detail::get_mem_block()'
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x19e): undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x254): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x3c6): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.o: In function `bool boost::regex_match, std::allocator, std::allocator > >, char, boost::regex_traits > >(std::basic_string, std::allocator > const&, boost::match_results, std::allocator >::const_iterator, std::allocator > > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags)':
main.cpp:(.text._ZN5boost11regex_matchISt11char_traitsIcESaIcESaINS_9sub_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEEEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbRKSbIT2_T_T0_ERNS_13match_resultsINSJ_14const_iteratorET1_EERKNS_11basic_regexISG_T3_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchISt11char_traitsIcESaIcESaINS_9sub_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEEEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbRKSbIT2_T_T0_ERNS_13match_resultsINSJ_14const_iteratorET1_EERKNS_11basic_regexISG_T3_EENS_15regex_constants12_match_flagsE]+0xe9): undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
main.o: In function `void Command::createVector(std::string const&, std::vector >&, double)':
main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x4a): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x7b): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0xac): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
main.o: In function `void Command::createVector(std::string const&, std::vector >&, unsigned int)':
main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x48): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x79): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
main.o:main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0xaa): more undefined references to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' follow
main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::match_match()':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE11match_matchEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE11match_matchEv]+0x371): undefined reference to `boost::match_results, std::allocator > > >::maybe_assign(boost::match_results, std::allocator > > > const&)'
main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::match_dot_repeat_slow()':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE21match_dot_repeat_slowEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE21match_dot_repeat_slowEv]+0x229): undefined reference to `boost::re_detail::get_mem_block()'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1

似乎根本找不到Boost :: Regex。请注意,这是需要编译并链接到您的应用程序才能工作的Boost库之一。以下是假设您已获得编译版本并且它位于系统的库目录中。

链接时,库和目标文件通过命令行参数传递给GCC的顺序非常重要。由于某种原因,2009年与海湾合作委员会合作的现在已不再适用。这可以通过更改make将参数传递给GCC的顺序来解决。

在项目根目录中找到Makefile,然后找到第6行:

$(CXX) $(LINK) -o $@ $^ $(LIBS)

在这里,您可以看到make在目标文件之前传递包含Boost库的链接器开关。 (如果你不能,请不要担心。你不必理解Makefile遵循这个解释。)为了使这个工作与当前的GCC,我们将改变参数的顺序。 Makefile的第6行应如下所示:

$(CXX) -o $@ $^ $(LIBS) $(LINK)

保存并再次运行make。现在编译和链接应该没有错误。

警告:#warning此文件至​​少包含一个已弃用或过时的标题

您仍会看到编译器警告,告诉您正在使用已弃用的头文件。您可以忽略此警告。但是,有可能更新版本的GCC没有附带此头文件,编译将失败。

如果你想修复它,请按照以下方式进行修复。

问题在于io/serialize.h,其中包括<ext/hash_map>。 C ++ 11标准replaces this with unordered_map。所以我们修改代码来使用它。第128行将是

typedef __gnu_cxx::hash_map<key_type, data_type> HashMap;

将此更改为使用unordered_map,如下所示:

typedef std::unordered_map<key_type, data_type> HashMap;

现在我们还需要修复标头。删除<ext/hash_map>的包含,并用

替换第26行
#include <algorithm>
#include <unordered_map>

需要<algorithm>包含,因为显然<ext/hash_map>还为std::sort提供了std::reversehash_map。这些函数现在位于<algorithm>标题中,代码依赖于此文件包含这些函数的事实。

由于这是一个C ++ 11特性,我们需要告诉GCC我们需要支持。转到项目根目录中的compiler.make,找到应为

的第6行
CXXFLAGS = $(DEBUG) $(WARNING) $(OPTIMIZER)

在该行的末尾添加开关以使用C ++ 11:

CXXFLAGS = $(DEBUG) $(WARNING) $(OPTIMIZER) -std=c++11

再次运行make cleanmake,您的代码应该编译而不会出现任何错误或警告。

相关问题